Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

github

gerrit

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.

like image 795
Darshan L Avatar asked Dec 14 '17 07:12

Darshan L


People also ask

Is change-ID and commit ID same?

It is independent of the commit id. To avoid confusion with commit ids, Change-Ids are typically prefixed with an uppercase I . Note that a Change-Id is not necessarily unique within a Gerrit instance. It can be reused among different repositories or branches (see below, change-upload).

Is commit ID and Sha same?

@SergioTulentsev The commit ID is always exactly the SHA1 of the commit; in most contexts, you can specify an unambiguous prefix of the commit ID as an equivalent reference to the commit.

What is Gerrit change-ID?

Gerrit allows attaching those 2 commits to the same change, and relies upon a Change-Id line at the bottom of a commit message to do so. With this Change-Id, Gerrit can automatically associate a new version of a change back to its original review, even across cherry-picks and rebases.

What is SHA in Gerrit?

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.


1 Answers

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

like image 141
gus3001 Avatar answered Oct 13 '22 12:10

gus3001