cherry-pick a commit and keep original SHA code

blameless75 picture blameless75 · Feb 3, 2013 · Viewed 27.2k times · Source

I would like to cherry-pick a commit on a fetched remote while keeping it's original SHA commit code (my current branch is based on this remote which I resetted to a previous state).

Answer

Marco Leogrande picture Marco Leogrande · Feb 3, 2013

A git SHA hash is computed from different pieces of information:

  1. The tree it refers to; basically, the current content of the repository in the branch in which the commit appears.
  2. The SHA of the parent commit(s).
  3. The commit message.
  4. The author information: name, email and timestamp.
  5. The committer information: name, email and timestamp.

Even if you edit a cherry-picked commit so that the tree, the commit message, the author and committer information are exactly the same, the SHA of the parent commit (or commits, if dealing with merge commits) will be always different. So, you will not be able to generate the same SHA hash after a cherry-pick (unless you find a SHA collision ;) ).