Single Commit Revert

  1. Get the SHA1 ID.
  2. git checkout BRANCH
  3. git revert SHA1ID

Multiple commits in a single revert

If you want to roll back a bunch of commits, you could do multiple reverts. But if you want the reverts to be a single commit:

  1. Get the SHA1 IDs.
  2. git checkout BRANCH
  3. git revert --no-commit SHA1ID
    • Repeat for each SHA1 ID
  4. git commit

Don't propogate a revert upstream

You might want to revert a buggy change on one branch while keeping it on upstream branches. For example, you have a buggy fix on V7_8_1-branch, and need to revert it because it missed the 7.8.1 release deadline. However, you've been merging your work forward to V7_8-branch and master, and you'd like to keep your work there. If you skip merging, someone in the future might do the merge not realizing an undesirable commit is in there and clobber your work.

  1. Get the SHA1 ID.
  2. git checkout V7_8_1-branch
  3. git revert SHA1ID
  4. git checkout V7_8-branch

If you just want to ignore the revert entirely, you can say:

  1. git merge -s ours V7_8_1-branch

If instead you want part of the revert, or want to make changes:

  1. Merge the revert in, but don't commit yet:
    git merge --no-commit V7_8_1-branch
  2. Identify files that were reverted, but that you don't want to revert:
    git status
  3. For each file that you don't want to revert:
    git checkout HEAD FILENAME
  4. You can edit files here as well.
  5. Add and commit your changes as usual
    git add FILENAME
    git commit