Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created April 22, 2010 08:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottwb/374977 to your computer and use it in GitHub Desktop.
Save scottwb/374977 to your computer and use it in GitHub Desktop.
Get the SHA of some git branch.
# Get the SHA of some branch. There must be a better way to do this.
git log -1 --pretty=oneline origin/somebranch | sed -E "s/^([^[:space:]]+).*/\1/"
@joninvski
Copy link

Didn't work.
To achieve the same I did:

git log -1 --pretty=oneline master | cut -d ' ' -f 1

@scottwb
Copy link
Author

scottwb commented Jan 29, 2011

I'm surprised this didn't work for you. I've been using it in some workflow-management scripts for a few months on both Linux and OS X without any problems, and just tried it again on my mac and it seems to work fine.

However...I like your way better - much easier to read :)

@scottwb
Copy link
Author

scottwb commented Jan 29, 2011

This just in: Someone posted a comment on my blog about this with an even better way:

git log -1 --pretty=format:%H

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