Search code examples
gitgithubgit-mergegit-commit

How to undo faulty commit without delete


Instead of deleting a faulty commit from master branch, is there a good way to add a new commit on top that somehow reverts the same changes as the faulty commit introduced?

In other words, we merged a commit that introduced a regression so we want to "undo that commit" but we'd rather not delete the commit somehow since then existing feature branches would have to be forced merged/pushed to master.


Solution

  • Use git-revert.

    git revert <commit>
    

    It creates a new commit that negates the changes the specified commit introduced.