Revert pushed branch to a concrete commit

江枫思渺然 提交于 2019-12-05 12:40:47

The -m number option specifies which of the parents you want to revert to (since a merge has multiple parents).

So you want git revert -m 1 HEAD or git revert -m 1 SHA_OF_MERGE_COMMIT (assuming you did git checkout master; git merge devel;)

Mark Longair

If you just want to make the state of master exactly the same as professional-1.1.2, while avoiding rewriting history and force-pushing, you can just create a new commit on top of master that represents the same state of the project as professional-1.1.2. You can do that with the following steps:

# Check that "git status" is clean, since the steps that follow will throw
# way uncommitted changes:
git status

# Set the index (staging area) to be as it was at professional-1.1.2:
git read-tree professional-1.1.2

# Create a commit based on that index:
git commit -m "Reverting to the state at professional-1.1.2"

# Your working tree will still be as it was when you started, so
# you'll want to reset that to the new commit:
git reset --hard

As an alternative, you can follow the steps suggested in this answer by Charles Bailey, which accomplishes the same thing, but is slightly more confusing, I think (even though the steps I've suggested involve the "plumbing" command git read-tree).

If you are a daredevil (recovering from an upstream rebase could be necessary for all other committers)

git checkout yourbranch
git reset HEAD <commit-hash>
git push origin yourbranch -f
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!