git 存储库中当前分支上的根提交是否有特殊名称(例如 HEAD、FETCH_HEAD)?

发布于 2024-09-25 19:25:54 字数 192 浏览 1 评论 0原文

我发现自己出于各种原因提到了根提交。我通常会创建一个名为 firstroot 的标签以使其更容易,但我最近一直在处理相当多的存储库,甚至这种手动标记也变得相当乏味。

有没有一种简单的方法来引用根提交,类似于 HEADFETCH_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

没有你我更好 2024-10-02 19:25:54

我只看到将与您相关的第一次提交标记为当前唯一的解决方案。
这样,您可以通过命名良好的标签来引用它,而不是通过日志查找其 SHA1。

注意:Git 存储库中可以有多个“根”提交(即没有任何父级的多个提交)
例如,请参阅此线程Jakub Narębski 的回答:

更不用说您可以在 git 存储库中拥有多个根(没有父项的多个提交)。
除了独立分支(如“man”、“html”或“todo”)之外,它通常是吸收或子树合并其他项目的结果.
在 'master' 分支中有 5 个或更多根:加入 'git-tools' (mailinfo / mailsplit ),吸收了 gitweb,并子树合并了 gitkgit-gui

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:

Not to mention that you can have multiple roots (multiple commits with no parent) in git repository.
Besides independent branches (like 'man', 'html' or 'todo') it is usually result of absorbing or subtree-merging other projects.
In 'master' branch there are 5 roots or more: joined 'git-tools' (mailinfo / mailsplit), absorbed gitweb, and subtree-merged gitk and git-gui.

陪你搞怪i 2024-10-02 19:25:54

要在 git 存储库中查找所有根提交(从任何本地分支开始)的 SHA-1 标识符,您可以使用以下命令:

$ git rev-list --parents --all |
  grep -v ' '

然后您可以使用 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:

$ git rev-list --parents --all |
  grep -v ' '

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 from git rev-list invocation contains at least one space separating commit id from its parent id(s).

The option --all means that git rev-list works as if all the refs in refs/ are listed on the command line as <commit>.

倚栏听风 2024-10-02 19:25:54

可以使用 Works 来获取与 HEAD 相对应的“根”的 sha(头的父级的父级的父级的...父级,直到达到没有父级的提交)

git rev-list --topo-order --reverse HEAD | head -n 1

不是那么容易,但是您实际上 。如果历史记录中有多个收敛路径,您将获得其中提交次数最多的路径的根。

但我不能说我认为它有任何用处。大多数有理由无限深入地穿越历史的事物都已经知道如何进行。

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

git rev-list --topo-order --reverse HEAD | head -n 1

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文