Is there any way to get a list of refs (including tags, branches, and remotes) that point to a particular commit in git?
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
refname :, e.g. master , heads/master , refs/heads/master. A symbolic ref name. E.g. master typically means the commit object referenced by refs/heads/master . If you happen to have both heads/master and tags/master , you can explicitly say heads/master to tell Git which one you mean.
git/refs/ . In Git, a head is a ref that points to the tip (latest commit) of a branch. You can view your repository's heads in the path . git/refs/heads/ . In this path you will find one file for each branch, and the content in each file will be the commit ID of the tip (most recent commit) of that branch.
git show-ref | grep $(git rev-parse HEAD)
shows all refs that point to HEAD
, the currently checked out commit.
git show-ref
shows all refs in your git repo.
git show-ref | grep "SHA goes here"
shows all refs that point to the SHA of a commit.
Human-readable format
For the last commit (ie, HEAD):
git log -n1 --oneline --decorate
Or to specify a particular commit:
git log -n1 --oneline --decorate fd88
gives:
fd88175 (HEAD -> master, tag: head, origin/master) Add diff-highlight and icdiff
To only get the tags/refs/remotes, pass this through sed
:
$ git log -n1 --oneline --decorate | sed 's/.*(\(.*\)).*/\1/'
HEAD -> master, tag: head, origin/master
For bonus points, add an alias for this:
decorations = "!git log -n1 --oneline --decorate $1 | sed 's/.*(\\(.*\\)).*/\\1/' #"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With