w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
git: How do I get the hash of the latest commit in the current branch when in detached HEAD state?

A problem is that the commit you are on (detached from the head) may actually be on several branches. If you only want one branch to be presented, you'll have to figure out some way to choose between them. But if you're happy seeing all the branches (with hashes) that contain your current commit you can say

git branch -v --contains HEAD

Here's some example output:

* (detached from 0bc85ab) 0bc85ab Git 1.9.2
  master                  cc29195 Git 2.0-rc0

you could trim that with grep and/or awk.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.