程序员开源工具技巧Git

git工作中使用总结续

2017-01-17  本文已影响114人  GuangchaoSun

git checkout

命令git checkout -- readme.txt意思就是,把readme.txt文件在工作区的修改全部撤销,这里有两种情况:一种是readme.txt自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态;一种是readme.txt已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。总之,就是让这个文件回到最近一次git commitgit add时的状态。

复原

场景1:当你改乱了工作区某个文件的内容,想直接丢弃工作区的修改时,用命令git checkout -- file
场景2:当你不但改乱了工作区某个文件的内容,还添加到了暂存区时,想丢弃修改,分两步,第一步用命令git reset HEAD file,就回到了场景1,第二步按场景1操作。

链接到github(三步走):

git remote add origin git@github.com:sunguangchao/hellow-world.git
git pull origin master
git push -u origin master

git pull --rebase

git bash出现vim的时候怎么退出?

git stash

从工作区添加到暂存区

git add .git reset HEAD <file_name>配合使用
git reset HEAD <file_name>可以将某文件从已经git add的列表中剔除出去

git cherry-pick commit_SHA

简而言之,cherry-pick就是从不同的分支中捡出一个单独的commit,并把它和你当前的分支合并。如果你以并行方式在处理两个或以上分支,你可能会发现一个在全部分支中都有的bug。如果你在一个分支中解决了它,你可以使用cherry-pick命令把它commit到其它分支上去,而不会弄乱其他的文件或commit

branch切换有关的命令

git branch -D #删除一个分支 
git branch -r # List remote branches
git branch -a # List local branches and remote branches
git branch -va #查看所有的远程分支  
git checkout -b <name> <remote_name> #创建并转到远程分支并改名字为name 
git push origin <name> #可以把本地创建的分支push到远端

Remove file from both repo and wroking directory : git rm <file>

tag相关的命令

git tag <name> #创建版本
git tag -r #查看远程版本
git tag -a <name> -m 'comment' #新建一个name tag,并添加comment
git push origin <tag_name> #把标签传送到远程服务器

merge流程

要想从一个branch merge回main_line可以通过merge commit IDtag或者branch三者中的一个来进行。

注意:在main-line上merge romote temporary branch的时候,不能有别人的提交,不然会失败,这是使用tempary branch的意义之一:可以减少这个过程的时间。

resolve the conflict

vim <file> #edit the conflict file
git add <file>
git commit -s 
上一篇 下一篇

猜你喜欢

热点阅读