简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM