Tag Archives: revert

Reverting a commit using git bash and bc3

After doing it the wrong way (see ‘wrong ways to revert a commit’), here is a good way to revert a commit that accidentally inserted in the past.

Reverting a commit

  1. Checkout the wanted branch, with the bad commit (lets mark it as SHA-1).
  2. git revert –no-commit SHA-1
  3. Solve merge problem
  4. Commit at the end

Solving merge conflicts on the way

Assuming your mergetool is configured.

Note: see ‘config BC3 as a mergetool‘ if you need to config your mergetool to BC3.

Solve your merge using the following command:

git mergetool

Config BC3 as a mergetool

Follow the instructions here:

http://www.scootersoftware.com/support.php?zz=kb_vcs#gitwindows

Note: If you use the Git for Windows’ Bash Command Prompt instead of the default Windows Command Prompt, you need to escape the $ character with .

Wrong ways to revert a commit

I think that its important to know the wrong ways of doing things also, here are some I tried and my personal conclusions:

Comparing folders and files

After trying that option here are some of this strategy disadvantages:

  1. Need to compare a lot of files ==> lot of effort.
  2. Do a 2 way comparison and can’t know what was the base change to decide. so, you guess by memory.
    1. This solution is limited by your memory power, the bigger the change you made the bigger the effort.
  3. Its not safe, you can make human errors and effect others commits.

Cherry-pick

Another solution proposed, sounds good but have its limits:

If the commit to undo is far in the past, you’ll need to:

  1. go to one commit before the bad commit
  2. start cherry-pick commits one after the bad one.
  3. merge 

While this is  a solution, what you doing is – undoing one commit – the hard way, and this post describes exactly how to do this strategy in one strike.

Resources

Git – git-revert Documentation.

git-revert(1) Manual Page

Vim Commands Cheat Sheet