What is the difference between Gerrit Change-ID and Commit SHA-1 in the context git commits?
Asked Answered
P

1

11

when we execute git log command, we see some information for each of the commit as below- Commit SHA-1 (Commit hash) Author Name and email Date Commit Title Commit Message Change-ID

I wanted to understand what is the difference between 1. Commit SHA-1 and 6. Change-ID.

Popeyed answered 14/12, 2017 at 7:39 Comment(2)
The docs explain that better than I'd be able to: git.eclipse.org/r/Documentation/user-changeid.htmlAleedis
Might be helpful. linkThermo
I
15

Commit SHA-1 (Commit hash) is a string that identifies a commit and is defined in a way that, if the commit is redone (with a amend, rebase or cherry-pick) or if anything in the commits history changes, the hash will be different. So, if you checkout a hash, you can be confident that you check out exactly the same commit with the same history. More info here: https://gist.github.com/masak/2415865

Gerrit Change-Id is also a hash string, but it is not part of git. It is something that is added later to commit messages so Gerrit can read it. This is only used by Gerrit. The use is the following. I make a new commit and send it to Gerrit. It has the Change-Id abc. When reviewed, if this commit has an issue, I have to fix it. The way I would do it is, amend the current commit. Amending will change the commit's SHA-1 but will not change the Change-Id if I do not change the commit message. Since now this new commit shares the same Change-id, when I send it to Gerrit, Gerrit will know that this new commit is a new version of the change abc and will group them together to facilitate reviewing. More info here: https://git.eclipse.org/r/Documentation/user-changeid.html

Immediacy answered 14/12, 2017 at 9:50 Comment(2)
So commit SHA-1 are generated by git system Whereas Change-ID is generated by gerrit system. Right?Popeyed
That is right. A change-id can also be automatically added to a change commit message via a gerrit git-hook. This can be installed on your machine.Immediacy

© 2022 - 2024 — McMap. All rights reserved.