cherry-pick a commit and keep original SHA code cherry-pick a commit and keep original SHA code git git

cherry-pick a commit and keep original SHA code


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 ;) ).


The SHA commit hash is made of from the state of the repository, using the whole history up to the point of the commit (branches not included). This means that you cannot keep the original hash on cherry-picking unless the whole history is the same, and in that case cherry-picking would make no sense.


According to your comments to other answers I think you simply want to reset to some remote commit. You can use git reset --hard <SHA> to do this. WARNING: This will discard all of your (uncommitted) changes in the working directory and all commits you did in this branch will no longer be accessible.

If this is not what you want (or you are not sure) please describe more clearly what you did and what you want to do or what you are trying to accomplish.