Get git SHA1 hash of a changeset (or diff) in a commit
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.
- In my repo, how long must the longest hash prefix be to prevent any overlap?
- generate a files sha1 hash to match githubs in php
- git fsck reporting “sha1 mismatch”
- How to “dereference” a string to a git sha1 hash?
- Why does Git use the SHA1 of the *compressed* objects rather than the SHA1 of the original objects?
- Assigning git's SHA of a directory without git
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.
2 Solutions collect form web for “Get git SHA1 hash of a changeset (or diff) in a commit”
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
You can get the SHA1 hash of the tree certain commit points to using
git show -s --pretty=format:%T master
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.