如何解决提交到错误的Git分支? [英] How to fix committing to the wrong Git branch?
问题描述
我只是对错误的分支做出了一个非常好的承诺。
如何撤消主分支中的最后一个提交,然后进行相同的更改并将它们加入到我的升级分支中?
I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?
推荐答案
如果您尚未推送更改,也可以进行软重置:
If you haven't yet pushed your changes, you can also do a soft reset:
git reset --soft HEAD^
这将恢复提交,但将提交的更改放回到索引中。假设分支机构相对于彼此是最新的,git会让你做一个结账到另一个分支机构,因此你可以简单地提交:
This will revert the commit, but put the committed changes back into your index. Assuming the branches are relatively up-to-date with regard to each other, git will let you do a checkout into the other branch, whereupon you can simply commit:
git checkout branch
git commit
缺点是你需要重新输入你的提交信息。
The disadvantage is that you need to re-enter your commit message.
这篇关于如何解决提交到错误的Git分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!