Questions tagged [git-hash]
30 questions
2626
votes
25 answers
How do I get the hash for the current commit in Git?
How do I get the hash of the current commit in Git?

Sardaukar
- 29,034
- 5
- 26
- 32
270
votes
12 answers
Get the current git hash in a Python script
I would like to include the current git hash in the output of a Python script (as a the version number of the code that generated that output).
How can I access the current git hash in my Python script?

Victor
- 23,172
- 30
- 86
- 125
141
votes
6 answers
How does Git compute file hashes?
The SHA1 hashes stored in the tree objects (as returned by git ls-tree) do not match the SHA1 hashes of the file content (as returned by sha1sum):
$ git cat-file blob 4716ca912495c805b94a88ef6dc3fb4aff46bf3c |…

netvope
- 7,647
- 7
- 32
- 42
58
votes
9 answers
Telling if a Git commit is a Merge/Revert commit
I am writing a script that requires checking whether a particular commit is a Merge/Revert commit or not, and I am wondering if there is a git trick for that.
What I came up with so far (and I definitely don't want to depend on the commit message…

Samer Buna
- 8,821
- 9
- 38
- 55
55
votes
2 answers
How does Git create unique commit hashes, mainly the first few characters?
I find it hard to wrap my head around how Git creates fully unique hashes that aren't allowed to be the same even in the first 4 characters. I'm able to call commits in Git Bash using only the first four characters. Is it specifically decided in the…

Ben
- 759
- 1
- 6
- 19
18
votes
1 answer
What are the dos and don'ts of custom objects and refs?
Let's say I want to write a small helper that allows to append some metadata to a repository in a way that can propagate to clones via refs. Simple example (a git-notes clone prototype that doesn't even attach the notes to any other git…

Tobias Kienzler
- 25,759
- 22
- 127
- 221
12
votes
1 answer
what does the hash from `git describe` refer to?
$ git describe --tags --long
test-1-g3c31c73
\_ ???
The g3c31c73 doesn't seem to point to anything... The doc says it's the abbreviated object name of the most recent commit, but it's not the HEAD commit hash, and find .git/objects -type…

dwelle
- 6,894
- 2
- 46
- 70
8
votes
2 answers
How can I get all symbolic names from a Git commit hash?
If a Git commit hash has multiple tags associated with it and/or is the head of multiple branches, is there a good way to list all of them?
I've looked through the options to git name-rev, git describe, and git symbolic-ref but haven't found any…

jamesdlin
- 81,374
- 13
- 159
- 204
4
votes
2 answers
Git objects SHA-1 are file contents or file names?
I am confused with how a file's actual contents are stored in .git.
For e.g. Version 1 is the actual text content in test.txt. When I commit (first commit) it to the repo, git returns a SHA-1 for that file which is located in…

appu
- 471
- 1
- 8
- 26
3
votes
2 answers
Is it possible to create a Git hash object outside a Git directory?
I am trying to get the git diff between 2 strings. The following command works:
git diff $(echo "my first string" | git hash-object -w --stdin) $(echo "my second string" | git hash-object -w --stdin) --word-diff
However, it fails if not executed…

danday74
- 52,471
- 49
- 232
- 283
3
votes
2 answers
Is a git commit hash trustable?
When using code from unknown third partys on github, I always make sure to check the code that no obvious backdoors that could compromise the security of my system exist.
The specific state of the repository I am reviewing is probably bound to a…

Zulakis
- 7,859
- 10
- 42
- 67
2
votes
1 answer
Difference between PowerShell's echo and CMD's echo
I get the following in PowerShell:
D:\> echo "Apple Pie" | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
D:\> "Apple Pie" | git hash-object --stdin
157cb7be4778a9cfad23b6fb514e364522167053
but in CMD.exe:
C:\>echo "Apple Pie" |…

Old Geezer
- 14,854
- 31
- 111
- 198
2
votes
1 answer
Determine branch name from git commit
I assume that a git commit hash (5743a31610d38064af35573b91e3bbe39d808b9b) will always map to 0 or 1 git branches? Is there a reliable way to trace what the branch name was when the git commit was created? From what I know a git branch is a pointer…

Alexander Mills
- 90,741
- 139
- 482
- 817
1
vote
3 answers
How to get all Git commit hash IDs of a master branch
I want to get all commit hash IDs of a master branch. Using the following command however only the latest commit id matches with the result. Old commit hash IDs don't belong to the master branch. Is there any other way to get commit hash IDs only…

Denis
- 33
- 1
- 7
1
vote
0 answers
EXPO SNACK: Error getting latest hash: Failed to get latest commit hash for repository
I am committing my repo to an expo snack and I am receiving the error:
Error getting latest hash: Failed to get latest commit hash for .
Is this because I am not using the proper URL to link to my repo or something else...I am not sure how to commit…

Matt Laszcz
- 373
- 3
- 20