16

I still find the behavior of git revert somewhat confusing. After significant pain and misunderstanding, I learnt that git revert negates a particular commit rather than reverting to that commit. I have not used git cherry-pick so far.

Can you elaborate on each of these two git commands? When and how do you prefer to use them?

haziz
  • 12,994
  • 16
  • 54
  • 75
  • 1
    Please first try to search Internet before requesting to duplicate documentation here. Here you have result from first page of Google results for 'git commands' search: quick-ref http://gitref.org/ and full commands reference http://git-scm.com/book/commands - my comment refer to original question before first edit "can you elaborate on each git command...", sorry if your intention was what Emil fixed in his edit. – MBO Oct 26 '12 at 11:23
  • @MBO: Yes my original question was: "Can you elaborate on each git command and when and how do you prefer to use it?" I have looked at google searches multiple times and do have 4 books on git. Using git revert was genuinely painful initially since for 1-2 months I understood it to mean reverting TO a particular commit and I could not understand the bizarre behavior it produced. I still find it a little confusing specially if there are interim commits between HEAD and the commit I am reverting OUT of. – haziz Oct 26 '12 at 11:52

1 Answers1

10

git cherry-pick is like "Convert the specified commit into a patch and apply this patch here".

git revert is like "Convert the specified commit into a patch, 'invert' this patch (like in patch -R) and apply it here".

Both commands can lead to conflicts.

Cherry-pick is used on unmerged (not reachable by parent links from current commit) commits. Revert is typically used on merged commits.

Undoing a revert commit requires making another revert commit (leading to commit messages like "Revert of 'Revert of ...'"), not cherry-picking reverted commit (as it is considered already merged).

Vi.
  • 37,014
  • 18
  • 93
  • 148