Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get all refs that point to a commit in git?

Is there any way to get a list of refs (including tags, branches, and remotes) that point to a particular commit in git?

like image 822
dbkaplun Avatar asked Jun 26 '13 19:06

dbkaplun


People also ask

How do you get details of a commit?

`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.

What is Refname in git?

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.

What is refs head git?

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.


2 Answers

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.

like image 102
dbkaplun Avatar answered Sep 21 '22 21:09

dbkaplun


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/' #"
like image 35
Tom Hale Avatar answered Sep 21 '22 21:09

Tom Hale