标签可以在 git filter-branch 和 rebase 之后自动移动吗?

发布于 2024-09-07 20:23:45 字数 902 浏览 9 评论 0原文

编辑问题归结为“也可以指示git rebase对标签进行rebase吗?”但对最初问题的回答也会有所帮助。


询问如何将过去添加到 git 存储库? 我遵循了这些说明。 <编辑>然后我重新调整基准以包含仅在快照中的文件,请参阅此处。</edit>由于历史被重写(通过 git filter-branch 或 git rebase 或两者?),所有标签仍然在原始时间线上*,我想以某种方式移动它们到新的。我认为我使所有带有标签的提交消息都是唯一的,因此我可以尝试编写一个使用它们的脚本,但更通用的 git move-tags;会更好。

那么,有没有办法解决“新时间线上的 N 个提交之后,旧时间线上的第 N 个提交被标记”的问题?除了明显的手动重新标记之外,任何其他解决方案也都很棒。

(请随意将这个可怕的长句子改成简单的英语...)

*) 嘿,git 解决了祖父悖论!

edit The question boils down to "Can git rebase be instructed to rebase tags, too?" But an answer to the original question would also help.


Asking How to prepend the past to a git repository? I followed these instructions. <edit>Then I rebased to include a file that was only in the snapshots, see here.</edit> Since history was rewritten (by git filter-branch or git rebase or both?) all tags are still on the original time line* and I'd somehow like to move them to the new one. I think I made all commit-messages with tags unique so I could try writing a script that uses them, but a more general git move-tags <from> <to> would be better.

So, is there a way to address "the commit which is N commits after on the new timeline such that the Nth commit after on the old timeline is tagged "? Any other solution except the obvious manual retagging would also be great.

(please feel free to correct that horribly long sentence into plain English...)

*) hey, git solved the grandfather-paradox!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

栖竹 2024-09-14 20:23:45

我写了一个脚本来执行此操作。

$ git-rebase-tags master
Rebasing 107 tags onto 'master'
Can't rebase tag 'staging-deploy-01' because there are no identical commits on 'master'
Pointed tag 'v0.0.11' at commit 81e16f2ca1bc7802547bf19c1dba1a68212eafff
Pointed tag 'v0.0.12' at commit 17051cc28084dd56ae56e96767bceee46217c02d
Pointed tag 'v0.0.13' at commit 5d795076ba4b33f81d327dcf9bff727cef7771a2
[...]

请参阅 gist.github.com/908381

但更好的是,使用 git-filter-branch(1) 中内置的 --tag-name-filter 选项。

I’ve written a script that does this.

$ git-rebase-tags master
Rebasing 107 tags onto 'master'
Can't rebase tag 'staging-deploy-01' because there are no identical commits on 'master'
Pointed tag 'v0.0.11' at commit 81e16f2ca1bc7802547bf19c1dba1a68212eafff
Pointed tag 'v0.0.12' at commit 17051cc28084dd56ae56e96767bceee46217c02d
Pointed tag 'v0.0.13' at commit 5d795076ba4b33f81d327dcf9bff727cef7771a2
[...]

See gist.github.com/908381.

But even better, use the --tag-name-filter option built into git-filter-branch(1).

夢归不見 2024-09-14 20:23:45

没有内置的方法可以使用 git 做你想做的事情。 “git rebase --tags”可能很有趣,但它不存在。

如果提交消息与您所说的相同,那么您可以遍历 refs/tags 中的每个标签,执行以下操作:

'git log -1 --pretty=oneline <tagname>'

将提交消息与完整列表进行比较:

'git log --pretty=oneline <newbranches>'

如果找到匹配项(并且 SHA1 哈希值不同),则执行以下操作:

'git tag --force <tagname> <new SHA1>'

There is no built in way to do what you want using git. 'git rebase --tags' might be interesting but it does not exist.

If the commit messages are identical as you say then you could go through each tag in refs/tags, do:

'git log -1 --pretty=oneline <tagname>'

Compare the commit message to the full list:

'git log --pretty=oneline <newbranches>'

If you find a match (and the SHA1 hash is different) then do:

'git tag --force <tagname> <new SHA1>'
为人所爱 2024-09-14 20:23:45

有一种方法可以使用 --tag-name-filter 选项使 git filter-branch 自动更新修改后的标签,如 在此答案中

There is a way to make git filter-branch automatically update modified tags using the --tag-name-filter option, as described in this answer.

单挑你×的.吻 2024-09-14 20:23:45

根据 Thomas Rast 的说法,http://git.661346.n2。 nabble.com/Rebase-with-tags-td5582971.html

列昂尼德·波多尔尼写道:

<块引用>

是否至少可以接收一组(旧提交,新提交)
成对,这样我就可以写一个小脚本来为我做到这一点?

重写后挂钩获取此列表,因此您可以根据需要使用它
到。

According to Thomas Rast at http://git.661346.n2.nabble.com/Rebase-with-tags-td5582971.html:

Leonid Podolny wrote:

Is it possible, at least, to receive a set of (old commit, new commit)
pairs, so that I will write a little script that will do that for me?

The post-rewrite hook gets this list, so you can use that if you want
to.

如果没有 2024-09-14 20:23:45

我已经整理了自己的 python 实现,git rebasetags

如果 rebase 是交互式的,您将看到一个 bash shell,您可以在其中进行更改。退出该 shell 后,标签将被恢复。

输入图片此处描述

来自这篇文章

I have put together my own python implementation, git rebasetags

In case the rebase is interactive, you will be presented with a bash shell where you can make the changes. Upon exiting that shell, the tags will be restored.

enter image description here

From this post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文