有很多方法可以重命名分支,但我将关注更大的问题:“如何让客户快速前进,而不必在本地弄乱他们的分支”。
先来一张速图:
这实际上很容易做到。但不要滥用它。整个想法取决于合并提交;因为它们允许快进,并将一个分支的历史与另一个联系起来。
重命名分支:
# rename the branch "master" to "master-old"
# this works even if you are on branch "master"
git branch -m master master-old
创建新的“master”分支:
# create master from new starting point
git branch master <new-master-start-point>
创建合并提交以具有父子历史记录:
# now we've got to fix the new branch...
git checkout master
# ... by doing a merge commit that obsoletes
# "master-old" hence the "ours" strategy.
git merge -s ours master-old
瞧。
git push origin master
这是可行的,因为创建merge
提交允许将分支快速转发到新修订版。
使用合理的合并提交消息:
renamed branch "master" to "master-old" and use commit ba2f9cc as new "master"
-- this is done by doing a merge commit with "ours" strategy which obsoletes
the branch.
these are the steps I did:
git branch -m master master-old
git branch master ba2f9cc
git checkout master
git merge -s ours master-old