at 符号 @
在 git 中经常使用到 specify revisions在不同的
方法。例如,
<ref>@{<date>}
在<date>
上指定其状态的引用.示例:
git diff master@{yesterday} master
.<ref>@{<n>}
在第 nth 个先验状态下指定引用。示例:
git diff master@{1} master
.@{-<n>}
指定之前 checkout 的第 nth 个分支 当前的。示例:
git checkout @{-5}
.<ref>@{upstream}
指定引用的上游分支。示例:
git diff master@{upstream} master
.
但是,@
在 git 命令中也以其他方式使用,比如
git rebase -i @~4
git log @^^..@
at 符号 @
是什么意思在这些例子中是什么意思?
最佳答案
As of Git version 1.8.5 ,at 符号 @
,没有前导分支/引用名称和序号 {n}
后缀,如 HEAD@{1}
和 master@{1}
,只是特殊 Git 引用 HEAD
的同义词/别名/快捷方式:
Instead of typing four capital letters "HEAD", you can say "@" now, e.g. "git log @".
所以对于这些命令
git rebase -i @~4
git log @^^..@
您可以简单地将 @
的 第一次 替换为 HEAD
(如果使用 Windows 或操作系统,则为 head
十)
git rebase -i HEAD~4
git log HEAD^^..HEAD
那么 HEAD
是什么意思呢?正如 official Linux Kernel Git documentation for specifying Git revisions 所解释的那样,HEAD
是您当前作为工作副本 checkout 的提交的特殊快捷方式引用(或者用 Git 术语来说,您的“工作树”):
HEAD names the commit on which you based the changes in the working tree.
您还可以阅读这些其他 Stack Overflow 问题,了解特殊引用 HEAD
的含义:
VonC 还发现了有关为什么在 this Stack Overflow answer (the last section at the bottom) 中选择 @
作为 head
的快捷方式的有趣信息。 .
请注意,就像 Git 经常发生的那样,虽然 @
是一个方便的快捷方式,但它并不总是 HEAD
的有效替代品.示例:
$ git bundle create temp.bundle @
Enumerating objects: 25, done.
Counting objects: 100% (25/25), done.
Compressing objects: 100% (20/20), done.
Total 25 (delta 3), reused 0 (delta 0), pack-reused 0
$ git bundle list-heads temp.bundle
c006e049da432677d1a27f0eba661671e0524710 refs/heads/master
$ git bundle create temp.bundle HEAD
Enumerating objects: 25, done.
Counting objects: 100% (25/25), done.
Compressing objects: 100% (20/20), done.
Total 25 (delta 3), reused 0 (delta 0), pack-reused 0
$ git bundle list-heads temp.bundle
c006e049da432677d1a27f0eba661671e0524710 HEAD
在这种情况下,使用 @
更像是 master
(HEAD
恰好指向的分支)的替代品,而不是对于 HEAD
。如果您稍后尝试从生成的包中获取,如果您使用了 @
,则必须指定要获取的引用 (master
),而您不会如果您明确指定了 HEAD
,则必须这样做。
关于git - "at"@ sign/symbol/character 在 Git 中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17910096/