GIT Learning
一、Why Git
1.1 Git是分布式的,本地的版本管理
chect out代码后会在自己的机器上克隆一个自己的版本库,即使你在没有网络的环境,你仍然能够提交文件,查看历史版本记录,创建项目分支,等不需要远程或架设服务器就能做到本地版本管理.
1.2 不污染子目录的track文件
svn每个子目录都要扔一个.svn.这个实在是.. .(我想很多人都碰到过svn lock folder的情况.实在让人气急败坏.实际上.svn文件就是罪魁祸首.各种clean up无果. delelte后svn up异常.真是.. 摔!.去你妹的svn.)
1.3 强大的branch
超轻量级的branch建立.(实际只是建立文件指针).推荐根据的git workflow的开发流程.将workspace分成几区.master dev feature hotfix区等.开发层次就出来了.
1.4 merge工具的强力
git根据commit ticket依次再进行一次merge.提高了merge成功率.避免svn merge中的难堪.即使merge失败.也不会生成乱七八糟的版本文件.简单修改后.commit就是.
二、 Git安装配置
2.1 安装
ubuntu: sudo apt-get install gitwindows: 去 http://code.google.com/p/msysgit/ 下载安装2.2 配置文件
你可以在.gitconfig文件中防止git的全局配置。文件位于用户的home目录。 上述已经提到每次提交都会保存作者和提交者的信息,这些信息都可以保存在全局配置中。
2.3 配置用户信息
# Configure the user which will be used by git
# Of course you should use your name
git config --global user.name "Example Surname"
# Same for the email address
git config --global user.email "your.email@gmail.com"
# Set default so that all changes are always pushed to the repository
git config --global push.default "matching"2.4 查看配置信息
git config --list2.5 SSH Keys
SSH key 可以让你在你的电脑和 Git @ OSC 之间建立安全的加密连接。
生成sshkey
# Creates a new ssh key using the provided email
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"在~/.ssh/id_rsa.pub中是生成的public key,复制文件中的全部内容并把他添加到ssh公钥管理中, Git @ OSC 的公钥管理页面如下链接: http://git.oschina.net/keys.
三. Git库管理
3.1 clone
可以clone命令去clone别人公开的代码了。git clone git://git.kernel.org/pub/scm/git/git.git
3.2 创建仓库,添加文件,提交修改
# Initialize the local Git repository
git init
# Add all (files and directories) to the Git repository
git add .
# Make a commit of your file to the local repository
git commit -m "Initial commit"
# Show the log file
git log先添加修改文件到提交索引,之后才能进行提交。
3.3 添加远程库
要添加一个新的远程仓库,可以指定一个简单的名字,以便将来引用,运行
git remote add [shortname] [url]:$ git remote add pb git://github.com/paulboone/ticgit.git
$ git remote -v
origin git://github.com/schacon/ticgit.git
pb git://github.com/paulboone/ticgit.git3.4 从远程仓库抓取数据
格式: git fetch [retmote-name]
git fetch pb3.5 推送数据到远程仓库
格式: git push [remote-name]
git push origin test:master // 提交本地test分支作为远程的master分支
git push origin test:test // 提交本地test分支作为远程的test分支git push pb master:testing3.6 分支
#新建分支test
git branch test
#切换到test分支
git checkout test
#将本地的test推送到远端
git push origin test:test
#切换到master分支
git checkout master
#将test分支合并到master分支
git merge test
#删除本地test分支
git branch -d test
#左面为空,远程的test分支将被删除
git push origin :test
四. SVN迁移到GIT
4.1 先建立users.txt,格式如下:
gr = ge rui <forgerui@gmail.com>
4.2 或者通过以下命令获取用户列表(需要perl支持)
$ svn log --xml | grep -P "^<author" | sort -u | \
perl -pe 's/<author>(.*?)<\/author>/$1 = /' > users.txt4.3 获取svn版本库信息:
$ git svn clone http://192.168.135.115:8080/svn/fpp
--authors-file=users.txt --no-metadata -s fpp4.4 将所有的旧分支都变成真正的 Git 分支,所有的旧标签也变成真正的 Git 标签
进入到项目的目录,运行如下命令:
$ cp -Rf .git/refs/remotes/tags/* .git/refs/tags/
$ rm -Rf .git/refs/remotes/tags
$ cp -Rf .git/refs/remotes/* .git/refs/heads/
$ rm -Rf .git/refs/remotes4.5 新增远程服务器
git remote add myproject git@git.oschina.net:bairuiworld/myproject.git4.6 让所有分支标签都上传
git push myproject --all
欢迎访问我的个人主页: www.forgerui.tk
GIT Learning的更多相关文章
- Git Learning - By reading ProGit
Today I begin to learn to use Git. I learn from Pro Git. And I recommend it which is an excellent bo ...
- Git Learning Part III - working remotely (Github)
help document of Github : https://help.github.com/ 1 upload 1.1 new update Initialize a repository ...
- Git Learning Part II - Working locally
file status life circle basic: modified: Examples: untracked: unmodified: modified: Git branching ...
- Git Learning Part I - Install Git and configure it
Why we need 'Git' GIt version control: 1. record the history about updating code and deleting code 2 ...
- git 学习(1) ----- git 本地仓库操作
最近在项目中使用git了,在实战中才知道,以前学习的git 知识只是皮毛,需要重新系统的学一下,读了一本叫 Learn Git in a Month of Lunches 的书籍,这本书通俗易懂,使 ...
- Git初级
一,安装git 一键安装 Mac 或 Windows. 二,下载一个工具书 Git 命令手册 free Git cheat sheet 三,安装完成之后需要先配置两个基本配置:用户名和邮箱 $ git ...
- Git/Github Learning
通过网上查找资料,我了解到Git/Github是一款免费.开源的分布式版本控制系统,它可以敏捷高效地处理任何或小或大的项目.同时,它是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的 ...
- Learning Git by Animations
https://hujiaweibujidao.github.io/blog/2016/05/20/learning-git-by-animations/ http://learngitbranchi ...
- Git命令回顾
团队从Eclipse迁移到Android Studio之后,也从SVN迁移到Git了. 一直忙于需求迭代无暇做迁移,现在才开始做,相见恨晚,好东西,高大上,词穷. 回顾和记录一下git的一些基本操作. ...
随机推荐
- Codeforces Round #290 (Div. 2) B. Fox And Two Dots dfs
B. Fox And Two Dots 题目连接: http://codeforces.com/contest/510/problem/B Description Fox Ciel is playin ...
- Socket编程学习之道:揭开Socket编程的面纱
对TCP/IP.UDP.Socket编程这些词你不会非常陌生吧?随着网络技术的发展.这些词充斥着我们的耳朵. 那么我想问: 1. 什么是TCP/IP.UDP? 2. S ...
- MyEclipse7.0破解下载
MyEclipse7.0 下载地址:downloads.myeclipseide.com/downloads/products/eworkbench/7.0M1/MyEclipse_7.0M1_E3. ...
- Windows平台下libevent库的使用
1 引子 手头上有一个使用了4个年头的HttpClient库,自己封装的,对于集成了IE浏览器的应用程序很友好.但最近想把产品扩展到Chrome和FireFox阵营,萌发了重构HttpClie ...
- mongodb目录
1. mongodb 数据库操作--备份 还原 导出 导入 2. ubuntu下mongodb启动脚本 3. mongodb实现远程连接 4. 用java在客户端读取mongodb中的数据并发送至服务 ...
- QT核心编程之调试技术 (g)
Qt应用程序的调试可以通过DDD进行跟踪调试和打印各种调试或警告信息.DDD(Data Display Debugger)是使用gdb调试工具的图形工具,它安装在Linux操作系统中,使用方法可参考D ...
- 二分查找实现(Jon Bentley:90%程序员无法正确实现)
二分查找实现(Jon Bentley:90%程序员无法正确实现)作者:July出处:结构之法算法之道引言Jon Bentley:90%以上的程序员无法正确无误的写出二分查找代码.也许很多人都早已听说过 ...
- LeetCode20 Valid Parentheses
题意: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- 收藏一部山地车教学视频,Fabien Barel主讲及动作示范
视频是由曾多次获得UCI速降赛的冠军车手Fabien Barel主讲及动作示范,讲解山地车越野的装备以及基本动作.视频中的要点说明我已经手录为文本,如果视频中没有看清的地方,也可以看文字. 骑行装备 ...

