一、git粗记
将另一个分支的某次提交所做的更改合并过来
git cherry-pick [commitID]
如果有冲突会提示如下
error: could not apply a968f8c1c3... [commit时的备注]
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
-
此时需要去解决项目中的冲突,等冲突解决完成之后,执行如下指令
git cherry-pick --continue
执行之后会进入vi编辑界面,可以输入相关信息(相关信息是啥 待深究),也可以直接输入
:wq
,执行保存并退出操作-
如果撤销此次cherry-pick,可执行如下指令
git cherry-pick --abort
查看本地分支与远端分支的关联关系指令
git branch -vv
建立线上线下分支的关联关系
git branch --set-upstream-to=origin/[远端分支名] [本地分支名]
二、分支操作
-
建立本地分支与远端分支之间的关联关系
git branch --set-upstream-to=<远程分支名> <本地分支名>
eg: git branch --set-upstream-to=origin/search/10.8.5/topic search/10.8.5/topic
-
删除远程分支
git branch -d -r <远程分支名>
eg: git branch -d -r origin/search/10.8.5/topic
-
删除本地分支
git branch -d <本地分支名>
-
取消本地分支与远端分支之间的关联关系,切换到对应的本地分支下,执行如下指令
git branch --unset-upstream
f -
重命名已经存在的本地分支:
Git branch -m <本地分支原名> <本地分支新名>
eg: git branch -m search/10.9/story_364_webcore_listen search/10.9.5/story_364_webcore_listen
三、分支信息查看操作
-
查看所有的存在本地分支以及远端分支
git branch --all
-
查看所有远端分支
git branch -r
-
查看本地分支与远端分支之间的关联关系
git branch -vv
四、更改提交相关操作
-
将本地分支的commit push到远程
git push origin <远程分支名>:refs/for/<本地分支名>
eg: git push origin search/10.8.5/topic:refs/for/search/10.8.5/topic
-
暂时存储本地的更改
git stash
-
恢复本地暂存的更改
git stash list
git stash apply
-
清空本地暂存的更改
git stash clear
-
放弃本地所有未push的commit
git reset --hard <commitID>
git reset --hard head
-
放弃已经push到远端的commit
git reset --hard <commitID>
git push origin <分支名> --force
-
将多个commit合并为一个commit
rebase -i
-
查看某次提交的更改
git show <commitId>
-
查看某次提交中某个文件的变化
git show <commitId> filename
-
可以看到fileName相关的commit记录
git log filename
-
可以显示每次提交的diff
git log -p filenam
找回误删除的代码
git fsck --lost-found
会log出每次对文件的修改记录对应的id, 通过git show <id>
查看对应id的更改内容,如果确认要找回的是这个id, 再通过git merge <id>
将丢失的内容还原。
未完待续篇