为什么 git 标签没有出现在任何分支上?
Why doesn’t a git tag show up on any branch?
我克隆了 mosquitto repo that has tag v1.4.9
。但是,标记的提交似乎不在分支上。
怎么会这样?作者是否真的在自己的仓库中保留了一个分支,但只将标签从该分支推送到 GitHub?或者他只是对标签做出承诺?
我把tag做成了本地分支
$ git checkout -b work149 v1.4.9
并查看分支上的最后一次提交:
$ git log -1
commit 91bfd82491f90e24b6fe9c036f0b04a1f5c14a89
Merge: bf959ef 2d0af73
Author: Roger A. Light <roger@atchoo.org>
Date: Thu Jun 2 22:05:34 2016 +0100
Merge branch 'fixes'
此提交比 fixes
分支早一个。
使用 git log --graph
我可以看到同一分支上的早期提交(不是 fixes
分支,而是我试图理解的分支):
* | commit bf959ef9b0ae0e4d74bf80158ffb0b7c69da533d
|\ \ Merge: 646e0a0 5cca6b4
| |/ Author: Roger A. Light <roger@atchoo.org>
| | Date: Sun Feb 14 14:38:42 2016 +0000
| |
| | Merge branch 'fixes'
| |
如何判断标签是否在分支上,在哪个分支上?最左边的垂直条是否表示一个分支,该分支在遥控器上在哪里?
这是一种常见的做法吗?
discussion thread “Git pull doesn’t get the tags” 提到“正在跟踪的分支负责人”和“未提交”。我想知道 git clone
命令是否将克隆配置为不跟踪远程上的所有分支,或者 repo 是否以某种方式将标签设为非提交?
我猜作者可能有一个包含 91bfd82491f 的分支,标记了那个提交,推送了标签,然后删除了这个分支。你也是正确的,作者可能有一个本地分支指向同一个提交,但只推送标签,而不是分支。
使用
检查哪个或哪些分支包含v1.4.9
git branch -a --contains v1.4.9
运行 该命令没有输出,这证实它不在自己的分支上。相反,寻找 v1.4.8
:
$ git branch -a --contains v1.4.8
* master
remotes/origin/HEAD -> origin/master
remotes/origin/debian
remotes/origin/master
在任何分支之外直接创建标记提交的一种方法是使用 detached HEAD 进行操作,也就是说 HEAD
不引用命名分支。在蚊子克隆中,您可以通过 运行
到达那里
git checkout v1.4.9
这会给你一个喋喋不休的警告。
Note: checking out 'v1.4.9'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 91bfd82... Merge branch 'fixes'
此时,git 将创建更多提交。例如:
$ touch look-ma-no-branch ; git add look-ma-no-branch
$ git commit -m 'Look, Ma! No branch!'
[detached HEAD 51a0ac2] Look, Ma! No branch!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 look-ma-no-branch
这个新提交 51a0ac2
在任何分支上都不存在,我们可以确认。
$ git branch -a --contains 51a0ac2
* (HEAD detached from v1.4.9)
为了好玩,我们也标记一下吧。
git tag -a -m 'Tag branchless commit' v1.4.9.1
用 git checkout master
切换回 master
分支,我们可以使用 git lola
(git log --graph --decorate --pretty=oneline --abbrev-commit --all
的别名)来查看新标签看起来与其相似祖.
$ git lola
* 51a0ac2 (tag: v1.4.9.1) Look, Ma! No branch!
* 91bfd82 (tag: v1.4.9) Merge branch 'fixes'
|\
| | * 1cd4092 (origin/fixes) [184] Don't attempt to install docs when WITH_DOCS=no.
| | * 63416e6 ;
| | * 5d96c3d [186] Fix TLS operation with websockets listeners and libwebsockts 2.x.
| |/
| * 2d0af73 Bump version number.
| | * 8ee1ad8 (origin/coverity-fixes) Merge branch 'fixes' into coverity-fixes
[...]
使用
确认它不存在于任何分支上
git branch -a --contains v1.4.9.1
因为你问了,不,这根本不是一个常见的 git 工作流程。
我错误地做了类似的事情:我正要推送一个新版本,我在我的电脑上提交了所有内容并添加了一个标签。
然后我做了git push --tags
,误以为它会推送master分支和标签。然后我在 github 上创建了一个版本。发布指向最后的更改,但 master 分支落后了。我不得不再次推动,一切都对齐了。
值得注意的是所有文件实际上都是用第一个命令推送的(我从输出中看到了它,你知道:创建增量等)。在第二次推送中,传输的字节报告为 0,所以我猜只有分支元数据被推送了。
我克隆了 mosquitto repo that has tag v1.4.9
。但是,标记的提交似乎不在分支上。
怎么会这样?作者是否真的在自己的仓库中保留了一个分支,但只将标签从该分支推送到 GitHub?或者他只是对标签做出承诺?
我把tag做成了本地分支
$ git checkout -b work149 v1.4.9
并查看分支上的最后一次提交:
$ git log -1
commit 91bfd82491f90e24b6fe9c036f0b04a1f5c14a89
Merge: bf959ef 2d0af73
Author: Roger A. Light <roger@atchoo.org>
Date: Thu Jun 2 22:05:34 2016 +0100
Merge branch 'fixes'
此提交比 fixes
分支早一个。
使用 git log --graph
我可以看到同一分支上的早期提交(不是 fixes
分支,而是我试图理解的分支):
* | commit bf959ef9b0ae0e4d74bf80158ffb0b7c69da533d
|\ \ Merge: 646e0a0 5cca6b4
| |/ Author: Roger A. Light <roger@atchoo.org>
| | Date: Sun Feb 14 14:38:42 2016 +0000
| |
| | Merge branch 'fixes'
| |
如何判断标签是否在分支上,在哪个分支上?最左边的垂直条是否表示一个分支,该分支在遥控器上在哪里?
这是一种常见的做法吗?
discussion thread “Git pull doesn’t get the tags” 提到“正在跟踪的分支负责人”和“未提交”。我想知道 git clone
命令是否将克隆配置为不跟踪远程上的所有分支,或者 repo 是否以某种方式将标签设为非提交?
我猜作者可能有一个包含 91bfd82491f 的分支,标记了那个提交,推送了标签,然后删除了这个分支。你也是正确的,作者可能有一个本地分支指向同一个提交,但只推送标签,而不是分支。
使用
检查哪个或哪些分支包含v1.4.9
git branch -a --contains v1.4.9
运行 该命令没有输出,这证实它不在自己的分支上。相反,寻找 v1.4.8
:
$ git branch -a --contains v1.4.8
* master
remotes/origin/HEAD -> origin/master
remotes/origin/debian
remotes/origin/master
在任何分支之外直接创建标记提交的一种方法是使用 detached HEAD 进行操作,也就是说 HEAD
不引用命名分支。在蚊子克隆中,您可以通过 运行
git checkout v1.4.9
这会给你一个喋喋不休的警告。
Note: checking out 'v1.4.9'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 91bfd82... Merge branch 'fixes'
此时,git 将创建更多提交。例如:
$ touch look-ma-no-branch ; git add look-ma-no-branch
$ git commit -m 'Look, Ma! No branch!'
[detached HEAD 51a0ac2] Look, Ma! No branch!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 look-ma-no-branch
这个新提交 51a0ac2
在任何分支上都不存在,我们可以确认。
$ git branch -a --contains 51a0ac2
* (HEAD detached from v1.4.9)
为了好玩,我们也标记一下吧。
git tag -a -m 'Tag branchless commit' v1.4.9.1
用 git checkout master
切换回 master
分支,我们可以使用 git lola
(git log --graph --decorate --pretty=oneline --abbrev-commit --all
的别名)来查看新标签看起来与其相似祖.
$ git lola * 51a0ac2 (tag: v1.4.9.1) Look, Ma! No branch! * 91bfd82 (tag: v1.4.9) Merge branch 'fixes' |\ | | * 1cd4092 (origin/fixes) [184] Don't attempt to install docs when WITH_DOCS=no. | | * 63416e6 ; | | * 5d96c3d [186] Fix TLS operation with websockets listeners and libwebsockts 2.x. | |/ | * 2d0af73 Bump version number. | | * 8ee1ad8 (origin/coverity-fixes) Merge branch 'fixes' into coverity-fixes [...]
使用
确认它不存在于任何分支上git branch -a --contains v1.4.9.1
因为你问了,不,这根本不是一个常见的 git 工作流程。
我错误地做了类似的事情:我正要推送一个新版本,我在我的电脑上提交了所有内容并添加了一个标签。
然后我做了git push --tags
,误以为它会推送master分支和标签。然后我在 github 上创建了一个版本。发布指向最后的更改,但 master 分支落后了。我不得不再次推动,一切都对齐了。
值得注意的是所有文件实际上都是用第一个命令推送的(我从输出中看到了它,你知道:创建增量等)。在第二次推送中,传输的字节报告为 0,所以我猜只有分支元数据被推送了。