Questions tagged [git-hash]

27 questions
2151
votes
20 answers

How to retrieve the hash for the current commit in Git?

I would like to retain (for now) the ability to link Git changesets to workitems stored in TFS. I already wrote a tool (using a hook from Git) in which I can inject workitem identifiers into the message of a Git changeset. I would also like to store…
Sardaukar
  • 23,924
  • 4
  • 26
  • 30
194
votes
10 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
  • 20,476
  • 27
  • 76
  • 108
131
votes
5 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
  • 6,297
  • 7
  • 29
  • 41
49
votes
8 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
  • 7,413
  • 8
  • 36
  • 53
36
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
  • 561
  • 1
  • 5
  • 17
9
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
  • 4,859
  • 1
  • 31
  • 53
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
  • 48,496
  • 10
  • 105
  • 134
8
votes
0 answers

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
  • 21,611
  • 21
  • 111
  • 204
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
  • 38,089
  • 29
  • 169
  • 214
3
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
  • 402
  • 3
  • 20
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
  • 10,411
  • 21
  • 87
  • 156
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
  • 1
  • 80
  • 344
  • 642
1
vote
1 answer

How to update files in my computer whenever they get updated in github?

I know this might sound stupid but I couldn't find a solution on the Internet. I'm working on a project in GitHub and every time someone adds a new file or some new code I have to download the whole files on my computer in order to open them from my…
1
vote
1 answer

Git Hash value of last un-pushed local commit

I have 3 local commits on my branch mainline which are ahead of the remote repo. How to get the hash value of the earliest local commit? Example: A <- HEAD(mainline) local B C D <- origin/mainline synced with remote How to get hash value of commit…
adimoh
  • 453
  • 7
  • 15
1
vote
1 answer

How to get reference to commits in git

Lets have a git master branch and at some moment lets fork branch for release (release branch will be called R1). Sometimes I need to push commit to both of them(master and R1). Usually I work on master branch, when I'm done I test it, cherry-pick…
Ondrej
  • 567
  • 5
  • 14
1
2