我在GitHub(Enterprise)上做了一个PR,提交很少。我的评论员在一次提交中发现了一个小错误:
* a401341c Did this (HEAD -> foo)
* 08e97f86 Did that
* 616cd4ad Done that
* f3c6151b Accomplished this
* 1af6e74f Fix this <-- Error there
* a099fc19 Finished this
* ab726eb3 Cherry-picked this (master, origin/master)
第一个解决方案是在1af6e74f
之后恢复所有提交,因为我不能在没有冲突的情况下还原它,然后通过更正重新应用所有提交:
* 0c99cf29 Reapply Did this (HEAD -> foo)
* 8806f36b Reapply Did that
* 572e1122 Reapply Done that
* 64ea3dc8 Reapply Accomplished this
* 81e20976 Fix this (this time correctly)
* d78a4534 Revert Fix this <-- Error there
* c0d817a9 Revert Accomplished this
* ed2bb3b2 Revert Done that
* ea34322a Revert Did that
* f81b78a3 Revert Did this
* a401341c Did this
* 08e97f86 Did that
* 616cd4ad Done that
* f3c6151b Accomplished this
* 1af6e74f Fix this <-- Error there
* a099fc19 Finished this
* ab726eb3 Cherry-picked this (master, origin/master)
然后git push
更新我的公关。
第二种解决方案涉及git push -f
git checkout 1af6e74f
git commit --amend -am "Fix this (with corrections)"
git rebase --onto a401341c f3c6151b HEAD # Not sure this will work as written
git branch -f foo HEAD
git push -f
以前的解决方案是一个很好的解决方案而后者总是一个糟糕的解决方案吗?
答案 0 :(得分:1)
问题:
旧分支与新分支之间的区别是什么(git diff a401341c 0c99cf29)?
它看起来像一个合理的补丁,它清楚地表明错误是如何修复的吗?
如果确实如此,只需获取新内容并将其作为旧分支上的新提交提交:
git checkout foo
# just to be on the safe side : work on a new temporary branch
git checkout -b wip
# go back to the old sate :
git reset --hard a401341c # <- original "Did this" commit
# get the content from new branch :
git checkout 0c99cf29 . # <- don't forget the "."
# check that it matches what you expect :
git diff [--cached] ...
git difftool -d [--cached] ...
# if OK : commit !
git commit
# make your local "foo" branch point to this commit :
git checkout foo
git reset --hard wip
git branch -d wip
# push :
git push origin foo