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).
So, you will not be able to generate the same SHA hash after a cherry-pick (unless you find a SHA collision ;) ).
Cherry-pick using Git commit hash In order to see the commit hashes for your current branch, simply run the “git log” command with the “–oneline” option in order to make it more readable. By default, the log command will display the commits from the history beginning until the top of your current branch.
This makes it useful for undoing changes, however, it's noteworthy to remember that cherry-picking will NOT delete the commit that was cherry-picked from the feature branch, so you will have to create a new feature branch and cherry-pick all your commits once more without the bug fix.
When you are performing a regular cherry-pick, you will get a new commit hash but the commit message will be the same. However, there is a way to append the origin of a cherry-pick to the commit message: by using the cherry-pick with the “-x” option.
A git SHA hash is computed from different pieces of information:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With