Skip to content

Instantly share code, notes, and snippets.

@ebouchut
Created January 15, 2013 15:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebouchut/4539565 to your computer and use it in GitHub Desktop.
Save ebouchut/4539565 to your computer and use it in GitHub Desktop.
git SHA1 to reference name conversion (back and forth)
git rev-parse: RefName ======> SHA1
git name-rev: SHA1 <===== RefName
# Convert the reference name HEAD to its corresponding SHA1
git rev-parse HEAD # Assuming for the sake of example that it outputs 1234567
# Convert the SHA1 (1234567) into its reference name (should output HEAD in our example)
git name-rev 1234567
# or else
git describe --all --contains 1234567
@ebouchut
Copy link
Author

Ouput the name of the current branch:

git name-rev --name-only $(git rev-parse HEAD)

@sangechen
Copy link

sangechen commented Jul 8, 2016

git branch --contains SHA1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment