在Git中,有没有办法让“友善”任意提交的名称? [英] In Git, is there a way to get the "friendly" name for an arbitrary commit?
问题描述
如果我使用 git-show-branch,那么在Git中有一个工具可以为所述提交找到一个友好的名字?
您可以使用git name-rev来获取您询问的表单。这种形式的一个问题是,相对于一个分支,它不是一个永久名称。因此,另一种方法是git describe,它根据给定提交的标签之前的距离来产生另一个友好名称。
例如:$ /b
$ b
srh @ devo16:〜/ src / git< master> $ git name-rev 3cd7388
3cd7388 master〜2
但是在我做了git pull之后,master〜2可能意味着别的东西。相比之下:
srh @ devo16:〜/ src / git< master> $ git describe 3cd7388
v1。 6.3.1-153-g3cd7388
现在v1.6.3.1-153-g3cd7388是一个永久名称。当然,它仍然有点长(尽管你可以通过指定--abbrev = 4来缩短最后的散列位),但是它告诉我们3cd7388在版本1.6.3.1之后有153个变化。
In Git, there are numerous ways to refer to a commit, including the full SHA hash or a shortened form of the hash (say, the first 6 characters or so). You can also name commits using a "friendly" syntax, like HEAD, HEAD^, HEAD^^, HEAD~3, and so on.
Given an arbitrary commit in SHA hash form, is there a tool in Git to find a "friendly" name for said commit?
If I use git-show-branch
, I get a list of revisions in "friendly" form, so I feel like there must be a way...I just can't find a tool to do it.
You can use "git name-rev" to get the form you are asking about. One problem with that form is that, being relative to a branch, it isn't a permanent name. So an alternative is "git describe" which produces an alternative friendly name based on how far ahead of a tag a given commit is.
For example:
srh@devo16:~/src/git <master>$ git name-rev 3cd7388
3cd7388 master~2
But then after I do a "git pull", master~2 could mean something else. By contrast:
srh@devo16:~/src/git <master>$ git describe 3cd7388
v1.6.3.1-153-g3cd7388
Now "v1.6.3.1-153-g3cd7388" is a permanent name. Of course, it's still a bit long (although you can shorten the hash bit on the end by specifying "--abbrev=4" for example) but it communicates that 3cd7388 is 153 changes after version 1.6.3.1.
这篇关于在Git中,有没有办法让“友善”任意提交的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!