cherry-pick a commit and keep original SHA code

前端 未结 5 528
孤独总比滥情好
孤独总比滥情好 2021-02-02 05:41

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 s

5条回答
  •  被撕碎了的回忆
    2021-02-02 06:02

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

提交回复
热议问题