Git 符号引用的推荐用法是什么?

发布于 2024-10-17 17:31:32 字数 957 浏览 5 评论 0 原文

下面的 shell 代码正确地创建了符号引用链

git symbolic-ref "first" "refs/heads/master"
git symbolic-ref "second" "first"
git symbolic-ref "nested/third" "second"
git symbolic-ref "refs/heads/fourth" "nested/third"

并且下面的 shell 代码正确地将最新创建的符号引用解析为 master 的提示。

git show-ref "refs/heads/fourth"

官方文档中没有描述这些用例(git-symbolic-ref 文档git-show-ref 文档)。

但是,以下内容不起作用

 git check-ref-format --print "first"

所以,我的问题是:

  • 可以在 refs/heads 目录中存储符号引用吗?
  • 可以链接符号引用吗?
  • 由于 check-ref-format 在传递 "first" 时失败,这是否意味着不建议在与 "HEAD" 相同的级别创建符号引用?或者也许这个命令不是为了处理符号链接?

我的目的是清楚地了解所支持的内容,并且我没有解决任何问题或从错误中受益。

The following shell code correctly creates a chain of symbolic references

git symbolic-ref "first" "refs/heads/master"
git symbolic-ref "second" "first"
git symbolic-ref "nested/third" "second"
git symbolic-ref "refs/heads/fourth" "nested/third"

And the following shell code correctly resolves the latest created symbolic reference to the tip of master.

git show-ref "refs/heads/fourth"

None of these use cases are described in the official documentation (git-symbolic-ref doc, git-show-ref doc).

However, the following doesn't work

 git check-ref-format --print "first"

So, my questions are:

  • Is it ok to store a symbolic reference within the refs/heads directory ?
  • Is it ok to chain symbolic references ?
  • As check-ref-format fails when being passed "first", does this mean that it's not recommended to create a symbolic reference at the same level than "HEAD"? Or maybe this command is not intended to deal with symbolic links ?

My intent is to get a clear understanding of what is being supported and that I'm not working around anything or benefiting from a bug.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

时光倒影 2024-10-24 17:31:32

我最终将此问题发布到 git 开发邮件列表。

Junio C Hamano,首席 git 维护者(+8700 次提交)为我提供了以下答案。

只有两种有效的类型
现在的符号引用:

  • .git/HEAD,指向 refs/heads/ 层次结构下的某个位置;

  • .git/refs/remotes/{一些远程名称}/HEAD,指向某处
    在 refs/remotes/{同一个遥控器下
    名称}/层次结构。

编写代码可以解析
递归符号引用,符号引用除外
以上两种,symrefs表示
指向其他地方,但所有这些
超出了设计范围
该机制的目的是什么
支持。代码对他们做了什么
(不会崩溃)不是设计,
但这只是一种未定义的行为。

如果我们
决定重新组织遥控器
1.8.0 中的跟踪层次结构。这
前者根本不会改变,而
后者将开始指向
refs/remotes/{相同的遥控器
name}/heads 层次结构。

我依稀记得 tg 滥用了 symref
将 .git/HEAD 指向有趣的机制
地点;它可能仍然这样做,
如果是这样的话我们应该
扩展上面的列表以涵盖该内容
用法。

I've eventually posted this question to the git development mailing list.

Junio C Hamano, the lead git maintainer (+8700 commits) provided me with the following answers.

There are only two valid kinds of
symrefs right now:

  • .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;

  • .git/refs/remotes/{some remote name}/HEAD, pointing at somewhere
    under refs/remotes/{the same remote
    name}/ hierarchy.

The code may be prepared to resolve
recursive symrefs, symrefs other than
the above two kinds, symrefs that
point at elsewhere, but all of them
are outside of the design scope of
what the mechanism was intended to
support. What the code do to them
(without crashing) is not the design,
but simply an undefined behaviour.

This won't change very much if we
decide to reorganize the remote
tracking hierarchies in 1.8.0. The
former won't change at all, and the
latter will start pointing at
refs/remotes/{the same remote
name}/heads hierarchy instead.

I vaguely recall tg abused the symref
mechanism to point .git/HEAD at funny
locations; it may still be doing so,
and if that is the case we should
extend the above list to cover that
usage.

女中豪杰 2024-10-24 17:31:32

通常,symrefs 位于 refs/ 下 - 至少,这是 git 套件所做的事情(例如,当使用 git filter-tree 时,你会得到 refs/original/...)。某些工具可能会选择忽略没有 refs/ 前缀的引用。

$ git symbolic-ref refs/first refs/heads/master
$ git check-ref-format --print refs/first
refs/first

Normally, symrefs live under refs/ — at least, this is what the git suite does (for example when using git filter-tree, you get refs/original/...). Some tools may choose to ignore refs that do not have the refs/ prefix.

$ git symbolic-ref refs/first refs/heads/master
$ git check-ref-format --print refs/first
refs/first
金橙橙 2024-10-24 17:31:32

希望符号链接可以更透明地使用并且也可以推送。它们可能成为新工作流程的强大工具。目前,如果我创建一个符号链接,然后推送,服务器将拥有哈希而不是相应引用中的链接。

It would be desirable that symbolic links can be used more transparently and can be pushed as well. They could be a powerful tool for new workflows. Currently, if I create a symbolic link and then push is the server will have the hash not the link in the corresponding reference.

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