Home > OS >  Commit amend for a cherry pick add a new change id
Commit amend for a cherry pick add a new change id

Time:11-12

After a cherry pick I use git commit --amend and I get generated a new change id so I get a new commit with 2 change ids.

How can I amend to not get a new change id?

Can at least the change-id generator be deleted temporary?

CodePudding user response:

What you're describing as a "change ID" is called a commit hash (c.f. this article).

It's created as a computational result (a hash) of all of the input in your commit, including (but not limited to) the message, contents, and the place where the commit is (its base or "parent").

When-ever you run git commit --amend, you are explicitly asking git to change (at least) the message and whatever file content you have staged since this commit. This means that, since the input will be different, the output hash will be different. Even if you keep the message and content the same, the computation is repeated at the current system time, giving a different hash.

There is no way to git commit --amend and keep the same hash. Furthermore, cherry-picking also changes the base and re-computes the hash, so a cherry-pick always yields a new hash. Hacking the hash to keep it the same is theoretically possible (ref) but it is not practically doable.

The "change-ID generator" does not exist -- git computes the hash based on a commit's exact contents and it must be cryptographically sound to other git clients. Therefore, it cannot be disabled, nor can it be (feasibly) defeated to ensure it puts out a specific hash.

  • Related