Git代码管理的应用

刚把SVN用熟后不久。有些项目就开始使用Git来管理代码版本了。
这里总结一些关于Git的使用。方便使用时查阅。 


一、代码检出和更新:

1、本地检出代码:git clone [email protected]:project.git

2、对已检出的代码更新到最新版本:git pull 

3、更新主干代码:git pull origin master

4、更新分支代码:git pull origin myBranch

二、代码提交:

5、提交代码到本地:git add index.html   git commit -m "Here is the description for this commit!"

6、提交到分支:如果是在分支下做的以上操作,则直接git push即可;或git push origin myBranch

7、提交到master:在master下add和commit之后,运行git push;或git push origin master

三、分支管理:

8、新建一个分支:git branch myBranch (分支新建之后记得立刻提交到服务器!)

9、提交新建的分支到服务器:git push origin myBranch

10、查看本地分支:git branch (当前所在的分支,用分支名前的*号标识)

11、分支之间的切换:git checkout myBranch (也可以切换到该项目下其他成员所建的分支)

12、提交代码到自己分支:git push origin myBranch

13、删除本地分支:git branch -d myBranch 或 git branch -D myBranch(强制删除)

14、删除服务端的分支:先删除本地分支,然后 git push origin :myBranch

15、更新本地数据库 git fetch origin,这样操作之后,远程如果有新的分支就可以知道了

16、更新本地之后,查看最新的所有分支:git branch -av,切换到某一分支 git checkout oneBranchName

四、git账号开通:

17、登录gitlab生成SSH-KEY,拷出文件内容(cat ~/.ssh/id_rsa.pub),在gitlab.xx.com/keys/new粘贴

五、其他常用命令:

18、查看git当前状态:git status

19、搜索modified状态文件:git status | grep modified (modified也可以换成delete等其他状态)

20、搜索并获取以冒号分隔的第二个字符:git status | grep modified | awk -F ":" '{print $2}'

21、对上述搜索结果运行add命令:git status | grep modified | awk -F ":" '{print $2}' | xargs git add

猜你喜欢

转载自tara-1128.iteye.com/blog/1931410