为什么git标签没有显示在任何分支上? [英] Why doesn’t a git tag show up on any branch?

查看:419
本文介绍了为什么git标签没有显示在任何分支上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了 mosquitto回购,其标签为

I cloned the mosquitto repo that has tag v1.4.9. However the tagged commit does not appear to be on a branch.

那怎么可能呢?作者实际上是否在自己的存储库中保留了一个分支,但仅将标签从该分支推送到GitHub?还是他只是对标签进行提交?

How could that happen? Does the author actually keep a branch on his own repo but only push tags from that branch to GitHub? Or does he just make a commit to a tag?

我将标签放入了本地分支

I made the tag into a local branch

$ git checkout -b work149 v1.4.9

并查看分支上的最后一次提交:

and looked at the last commit on the branch:

$ 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分支,而是我试图理解的分支):

With git log --graph I can see an earlier commit on the same branch (not the fixes branch, but a branch I'm trying to understand):

* |   commit bf959ef9b0ae0e4d74bf80158ffb0b7c69da533d
|\ \  Merge: 646e0a0 5cca6b4
| |/  Author: Roger A. Light <roger@atchoo.org>
| |   Date:   Sun Feb 14 14:38:42 2016 +0000
| |
| |       Merge branch 'fixes'
| |

您如何确定标签是否在分支上以及在哪个分支上?最左边的竖线是否指示分支,并且该分支在遥控器上的何处?

How do you find out whether a tag is on a branch and on which branch? Does the leftmost vertical bar indicate a branch and where is that branch on the remote?

这是常见的做法吗?

讨论线程"Git pull无法获取标签" 提到正在跟踪的分支头"和未提交".我想知道git clone命令是否将克隆配置为不跟踪远程服务器上的所有分支,或者存储库以某种方式使标记变为非提交?

The discussion thread "Git pull doesn’t get the tags" mentions "branch heads that are being tracked" and "non-commits." I wonder whether the git clone command configures the clone not to track all the branches on the remote or the repo has somehow made the tags into non-commits?

推荐答案

我的猜测是作者可能有一个分支,其中包含 91bfd82491f ,标记了提交,推送了标记,然后又删除了该分支.您还正确的是,作者可能有一个本地分支,该分支指向相同的提交,但仅推送了标签,而不是分支.

My guess is the author probably had a branch that contained 91bfd82491f, tagged that commit, pushed the tag, and then later deleted the branch. You are also correct that the author may have a local branch that points to the same commit but pushed the tag only, not the branch.

使用

git branch -a --contains v1.4.9

运行该命令不会产生任何输出,这表明它不在自己的分支上.相反,寻找v1.4.8:

Running that command gives no output, which confirms that it is not on a branch of its own. In contrast, look for v1.4.8:

$ git branch -a --contains v1.4.8
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/debian
  remotes/origin/master

直接在任何分支外部创建带标记的提交的一种方法是使用分离的HEAD进行操作,即HEAD不引用命名分支的地方.在mosquitto克隆中,您可以通过运行

One way to directly create a tagged commit outside any branch is to operate with a detached HEAD, that is where HEAD does not refer to a named branch. In the mosquitto clone, you can get there by running

git checkout v1.4.9

这会给您一个健谈的警告.

which gives you a chatty warning.

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将创建更多提交.例如:

At this point, git will create more commits. For example:

$ 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在任何分支上都不存在,我们可以确认.

This new commit 51a0ac2 does not exist on any branch, which we can confirm.

$ git branch -a --contains 51a0ac2
* (HEAD detached from v1.4.9)

为了娱乐,我们也对其进行标记.

For fun, let’s tag it too.

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的别名)可以看到新标签看起来与其祖先相似.

Switching back to the master branch with git checkout master, we can use git lola (an alias for git log --graph --decorate --pretty=oneline --abbrev-commit --all) to see that the new tag looks similar to its progenitor.

$ 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工作流程.

Because you asked, no, this is not at all a common git workflow.

这篇关于为什么git标签没有显示在任何分支上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆