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.

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.

  • How does bup (git-based image backup) computes hashes of stored objects
  • apparently same commits give different sha1, why?
  • 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
  • How is a Git Tag Object SHA1 Created?
  • How to assign a Git SHA1's to a file without Git?
  • Hash collision in git
  • In my repo, how long must the longest hash prefix be to prevent any overlap?
  • 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
    • 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.

    Git Baby is a git and github fan, let's start git clone.