git 存储库中当前分支上的根提交是否有特殊名称(例如 HEAD、FETCH_HEAD)?
我发现自己出于各种原因提到了根提交。我通常会创建一个名为 first
或 root
的标签以使其更容易,但我最近一直在处理相当多的存储库,甚至这种手动标记也变得相当乏味。
有没有一种简单的方法来引用根提交,类似于 HEAD
或 FETCH_HEAD
?
I find myself referring to the root commit for various reasons. I usually make a tag called first
or root
to make it easier, but I have been dealing with quite a few repositories lately and even this manual tagging is getting quite tedious.
Is there an easy way to refer to the root commit, something similar to HEAD
or FETCH_HEAD
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我只看到将与您相关的第一次提交标记为当前唯一的解决方案。
这样,您可以通过命名良好的标签来引用它,而不是通过日志查找其 SHA1。
注意:Git 存储库中可以有多个“根”提交(即没有任何父级的多个提交)
例如,请参阅此线程,Jakub Narębski 的回答:
I only see tagging that first commit relevant for you as the only current solution.
That way, you can refer to it through a well named tag instead of looking for its SHA1 through the log.
Note: there can be several "root" commits in a Git repo (i.e. several commits without any parent)
See for instance this thread, with Jakub Narębski's answer:
要在 git 存储库中查找所有根提交(从任何本地分支开始)的 SHA-1 标识符,您可以使用以下命令:
然后您可以使用
git show
检查它们。说明:
git rev-list
选项--parents
使其打印 空格分隔提交的所有父级列表(以“提交父级...”的形式)。因此,如果某个提交有任何父级,则 git rev-list 调用中的行至少包含一个空格,将提交 ID 与其父级 ID 分隔开。选项
--all
意味着git rev-list
的工作方式就好像refs/
中的所有引用都在命令行上列出为 < 提交>。To find SHA-1 identifiers of all root commits (starting with any local branch) in a git repository, you can use the following command:
You can then use
git show
to examine them.Explanation:
git rev-list
option--parents
makes it print space separated list of all parents of the commit (in the form "commit parent…"). Therefore if a commit has any parents, the line fromgit rev-list
invocation contains at least one space separating commit id from its parent id(s).The option
--all
means thatgit rev-list
works as if all the refs inrefs/
are listed on the command line as <commit>.可以使用 Works 来获取与 HEAD 相对应的“根”的 sha(头的父级的父级的父级的...父级,直到达到没有父级的提交)
不是那么容易,但是您实际上 。如果历史记录中有多个收敛路径,您将获得其中提交次数最多的路径的根。
但我不能说我认为它有任何用处。大多数有理由无限深入地穿越历史的事物都已经知道如何进行。
Not so easy, but you can get the sha of the "root" that corresponds to HEAD (head's parent's parent's parent's ... parent until a commit is reached that has no parent) using
Works for any commit actually. If there are multiple convergent paths of history, you'll get the root of the path that has the most commits in it.
I can't say that I see any use whatsoever for it, though. Most things that have any reason to traverse history an unlimited depth into the past already know how.