GIT – how do I copy SHA without mouse on OSX?
On OSX, often I go to the
git log in order to find a commit, usually a few back, copy it with my mouse, then rebase off of that.
How can I do this easily without using my mouse or memorizing it?
2 Solutions collect form web for “GIT – how do I copy SHA without mouse on OSX?”
Just memorize the first couple letters/numbers.
Git does not need the full hash to rebase, it only needs the first couple characters of it.
(minus the extra commit stuff)
Now, lets say you want the second one,
You can simply rebase on the first couple characters.
git rebase 11be
Further info: technically git only needs a unique start of a hash. So in this case,
git rebase 1 would be sufficient because no other commit hashes begin with a 1. However, in extreme cases you might need more than 4-5 characters (Very unlikely)
Also, feel free to use
git log -n to get only the last n number of commits. By keeping this to a low number, the commit is still usually on your screen when you call rebase, so you have no need to memorize. Just manually copy the first couple characters. Hint: If git flushes the log output once you hit ‘q’ to quit, you can use the command
git --no-pager log -n to get the output to “stick”.
For added info on git and rebase, if you knew you wanted to rebase exactly 4 commits, you could just use the
HEAD reference. Your current commit is
HEAD and 1 commit ago is
HEAD~1 etc. For example:
git rebase HEAD~4
3521260b7d04fc92eaeb9c70fa46999dc1ecda3d as the new
HEAD (since we are rebasing on
On OSX, you can use
So to get the SHA1 of your last commit in your clipboard:
git log -1 --format="%H" | pbcopy