Home > Enterprise >  Revert commit after another commit
Revert commit after another commit

Time:10-21

I have committed to master and someone else has then committed after me.

I need to revert my commit but keep the commit that was made after me.

Can I just revert my commit with git revert commit-hash and the commit made after me will be OK?

CodePudding user response:

You should do this:

# Save wrong commit into a branch

git checkout master
git branch "commit-after-me-branch-name"

# Revert master branch to your commit

git checkout master
git reset --hard "my-previous-commit-hash"

# Rewrite repository history

git push --force

CodePudding user response:

Yes, it should work, if you do not have any conflicts with the commits in front of the commit you are about to revert. With the reset command you would go back to your commit and delete all commits in front of yours

  •  Tags:  
  • git
  • Related