git - "at"@ sign/symbol/character 在 Git 中是什么意思?

标签 git

at 符号 @在 git 中经常使用到 specify revisions在不同的 方法。例如,

  1. <ref>@{<date>}<date> 上指定其状态的引用.

    示例:git diff master@{yesterday} master .

  2. <ref>@{<n>}在第 nth 个先验状态下指定引用。

    示例:git diff master@{1} master .

  3. @{-<n>}指定之前 checkout 的第 nth 个分支 当前的。

    示例:git checkout @{-5} .

  4. <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 的含义:

  1. HEAD and ORIG_HEAD in Git .
  2. What is git HEAD, exactly? .

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/

相关文章:

git - git merge 后,这个分支落后1次提交

c++ - qmake 与 Jenkins

git - 接收端不支持推送选项

ruby - 如何在 Travis Ruby on Rails 中输入 heroku 凭据

git - 我如何 git squash 更早地一起提交?

带有 LDAP 的 Gitolite 不工作

c# - 需要 Squirrel.Windows Update Manager.GitHub Update Manager Assistant

windows - "Open git bash here"和 "Open command prompt here"从 Windows 资源管理器上下文菜单中消失

包含版本号的 Git 日志

git - 如何在使用 Github 还原按钮还原 PR 后再次 PR 和 merge