开发者

Get git SHA1 hash of a changeset (or diff) in a commit

开发者 https://www.devze.com 2023-03-07 19:37 出处:网络
I\'m mostly integrating finished topic branches into the开发者_运维百科 main development branch, in git. While doing that I sometimes have to change the message of commit (improving, correcting spelli

I'm mostly integrating finished topic branches into the开发者_运维百科 main development branch, in git. While doing that I sometimes have to change the message of commit (improving, correcting spelling, ...) which results into a new commit with new SHA1 ID.

I would like to get the SHA1 hash of the changes in a commit. This would let us verify if any content of the changeset is altered or not after modyfying the commit message.

It would be great if we could get the SHA1 hash of the changeset of a sequence of commits too. Then we would be able to do interactive rebases where we squash commits and still end up with the same SHA1 hash of the changeset.


When git needs to tell whether a patch has already been applied, e.g. for git cherry, it uses git-patch-id to create a hash of the patch introduced by that commit. Perhaps that would suit what you're wanting to do? Or perhaps git cherry already does what you want? The documentation for those commands are:

  • git cherry
  • git-patch-id


You can get the SHA1 hash of the tree certain commit points to using

git show -s --pretty=format:%T master

where master is any commit specification.

Note that git doesn't track changesets, it tracks the whole repository, so this tree id represents the state of the whole repository after that commit, not the changes that were added by that commit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号