[英]Identifying a tag belongs to which branch in git
I first did repo sync to a manifest for a branch name myBranch.我首先将回购同步到分支名称 myBranch 的清单。 I then get the tags from
然后我从
git tag -l
Now I want to know using git that each tag obtained as a result of git tag -l was actually created on which branch.现在我想知道使用 git 作为 git tag -l 的结果获得的每个标签实际上是在哪个分支上创建的。 Please note: I do not want myBranch as the output but the remote branch name on which the tag was created.
请注意:我不希望 myBranch 为 output,而是创建标签的远程分支名称。
Keeping aside the fact that branches can be renamed or deleted at any time (without losing any commits, which can still be referenced in the path of another branch), the best you can do is:撇开分支可以随时重命名或删除的事实(不会丢失任何提交,仍然可以在另一个分支的路径中引用),您可以做的最好的事情是:
See " Show the original branch for a commit ", combined with " Git - how to tell which commit a tag points to ".请参阅“ 显示提交的原始分支”,结合“ Git - 如何判断标签指向哪个提交”。
(Ie, a combination of git rev-parse <tag>~0
with git branch --contains <sha1>
) (即,
git rev-parse <tag>~0
与git branch --contains <sha1>
)
This has nothing to do with the branch on which the tag was created , but rather the branch(es) which currently reference said tag.这与创建标签的分支无关,而是与当前引用所述标签的分支有关。
No such thing.没有这样的事。 Tags point to commits, and branches point to commits.
标签指向提交,分支指向提交。 A single commit can be pointed at (or be a parent of) dozens of different branches;
一个提交可以指向(或者是)几十个不同的分支; there is no way to narrow down one specific branch as "the owner of this tag".
无法将一个特定分支缩小为“此标签的所有者”。 The branch might have been deleted from upstream before you fetched it, and only the commit remains, as another example of why this can't work.
在您获取分支之前,该分支可能已从上游删除,并且仅保留提交,这是为什么这无法正常工作的另一个示例。
I was able to solve this in two ways我能够通过两种方式解决这个问题
Using the solution given by @VonC I was able to identify for the available tags its source branch使用@VonC 给出的解决方案,我能够为可用标签识别其源分支
for tag in $(git tag)
do
commit=$(git rev-parse $tag~0)
echo "$tag: $(git rev-parse $commit~0) | branch: $(git branch -r --contains $commit)" | grep branch
done
the output will look like output 看起来像
qa-test-integrated-v0.0.3d: 382d0553d189a8a1591667a3806ac98d0f11394a | branch: origin/HEAD -> origin/master
qa-test-integrated-v0.0.3e: 1a5329d611fe15db6704fe1ea3717b62df8c4320 | branch: origin/HEAD -> origin/master
tag-from-feature-branch: 851cb526e9f9e2c00a3b1e626c010038ecab7428 | branch: origin/feature/DPTGROGU-0000-support
Given the snippet above you can use any bash tool to filter related to a specific branch.鉴于上面的代码片段,您可以使用任何 bash 工具来过滤与特定分支相关的信息。
git tag --merged branch
试试这个:
branch=$(git for-each-ref | grep ${commit_num} | grep origin | sed "s/.*\///")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.