1

I have a commit on a branch I would like to undo.

The problem is there are commits on the branch after. If I revert that commit, will it still leave their changes intact?

Harry Blue
  • 4,202
  • 10
  • 39
  • 78
  • Have a look at interactive rebase: https://stackoverflow.com/questions/10018447/how-to-run-git-rebase-interactive-mode-to-remove-duplicate-commits – C-Otto Jan 08 '18 at 08:06

1 Answers1

7

git revert will create a new commit (on top of all the existing ones) which is the inverse of the commit you want to revert. So you aren't altering history, and only your changes will be reversed (unless someone edited the same lines afterwards, then you need to fix conflicts). This is the recommended way to reverse non-sensitive changes (sensitive changes include, for example, submitting of credentials to source control by accident)


git rebase -i will allow you to alter history so that your commit never existed on the branch. This will require a git push --force and will generally make your coworkers unhappy with you. Use it only if you know what you're doing.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308