- Fork 仓库更新
- 分支同步
- 修改commit信息
- p, pick = use commit
- r, reword = use commit, but edit the commit message
- e, edit = use commit, but stop for amending
- s, squash = use commit, but meld into previous commit
- f, fixup = like “squash”, but discard this commit’s log message
- x, exec = run command (the rest of the line) using shell
- d, drop = remove commit
Fork 仓库更新
Fork 后经过一段时间容易落后原仓库一些提交,这时需要更新Fork仓库进行同步。
- 原仓库为 Oriremote
- 主分支为 master
添加原仓库命名为ori,并拉取:
$ git remote add ori https://github.com/xxx/Oriremote.git $ git fetch ori
进行合并并push到master分支上:
$ git checkout master $ git merge ori/master $ git push origin master
查看Fork仓库的commit,已经更新为原仓库的最新状态。
分支同步
如果是在Fork之后新建分支进行修改,则需将master更新同步到新的分支上。
- Fork后新增修改分支 develop
- develop 是基于 master 的分支
直接合并,分支消失
$ git checkout master $ git merge develop $ git push
保持分支,只做更新
$ git checkout develop $ git rebase master $ git push —force
将master新增的commit补充到develop之前,再把develop的commit补充上。rebase本质是cherry-pick,最后可以强制提交,或者提交一个merge信息。
修改commit信息
还未push的commit
push之前很容易进行各种修改,包括message甚至是文件内容:
$ git commit —amend
可以在修改文件内容后使用amend,或者直接使用并修改message。修改完成后使用Ctrl+O保存,Ctrl+X退出。
已经push的commit
对于已经提交的commit,可以使用rebase(变基)进行更改:
$ git log $ git rebase -i
rebase会将最新提交到当前变基位置的commit列出,并提供以下选择:
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like “squash”, but discard this commit’s log message
x, exec = run command (the rest of the line) using shell
d, drop = remove commit
可以根据需要更改commit前的状态,只更改message可选择reword,合并commit可选择squash…
需要注意的是更改时会分离出新的头指针,更改结束后除了使用 —continue 回到原基址外还要合并头指针,如果更改内容涉及到文件可能需要merge,之更改message可以直接合并:
$ git reset HEAD
后续push即可,视情况选择添加—force参数。
作者:hwrenx
链接:https://www.jianshu.com/p/86fdfc4fc114