如果您只想 branchmaster
引用其内容与 branch 相同的新提交,并且branch
之间的增量是“更改所有内容以匹配分支的内容”,那很容易:master^
master
branch
$ git checkout branch
$ git symbolic-ref HEAD refs/heads/master
$ git status # you'll see what you're about to commit, here
$ git commit # make that new commit
请注意,此处不会引用master
分支历史记录。branch
如果您希望提交看起来像一个将所有内容更改为外观的合并branch
,这似乎可以解决问题,但我还没有很好地测试它:
$ git checkout master
$ git merge --no-commit -s ours branch # this sets up the merge
$ git rm -r . # this empties it out
$ git checkout branch -- . # this adds everything from branch
$ git status # again, just to see what you're about to commit
$ git commit # and maybe edit the message to note that you took "branch"
现在master^
是大师曾经的样子,master^2
是尖端的branch
。