Git,重写主分支和相关标签的历史记录
我刚刚经历了第一次重写我的一个存储库的历史(使用 git-filter-branch)。 问题在于该存储库有多个标签,重写后似乎与结果历史记录完全脱节。 我认为这是因为与标签相关的历史记录尚未被重写,因此它们必须指向旧的提交。 那么,我该怎么做才能将标签“应用”到新历史记录上。 一点 ASCII 艺术,也许更容易理解我的问题:
原始仓库:
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit
历史重写后 gitk --all
报告的仓库结构:
+ HEAD
|
|
|
|
|
|
|
|
+ Initial commit
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit
I've just had my first experience with rewriting the history of one of my repos (using git-filter-branch). The problem is that the repo had several tags, which after rewriting seem to be completely disconnected from the resulted history. I think this is due to the fact that the history associated with the tags hasn't been rewritten, so they have to point to the old commits. So, what can I do to "apply" the tags on the new history. A little ASCII art, maybe it's easier to understand my question:
Original repo:
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit
Repo structure reported by gitk --all
after history rewrite:
+ HEAD
|
|
|
|
|
|
|
|
+ Initial commit
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想要执行可以使用 git filter-branch 完成的更改,那么您可以使用
--tag-name-filter ,如上所述。
如果你想进行交互式变基,你需要其他东西。
这两件事都可以通过 git rebasetags 来完成。
如果 rebase 是交互式的,您将看到一个 bash shell,您可以在其中进行更改。 退出该 shell 后,标签将被恢复。
来自这篇文章
If you want to perform a change that can be done with
git filter-branch
, then you can use--tag-name-filter
as explained above.If you want to do interactive rebasing though, you need something else.
Both things can be accomplished with
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.
From this post
首先,您也必须重写标签,例如(如VonC 表示)通过使用
--all
选项重写所有引用。如果您有带注释的标签(重量级标签),您还必须使用
--tag-name-filter
选项,例如--tag-name-filter cat
。 请注意,您不能重写签名标签!First, you have to rewrite tags too, e.g. (as VonC said) by using
--all
option to rewrite all references.If you have annotated tags (heavyweight tags) you have also to use
--tag-name-filter
option, e.g. as--tag-name-filter cat
. Note that you cannot rewrite signed tags!看起来像这里描述的过程的最后一步
这个想法是从旧版本的存储库中读取标签,并将它们重新应用到新的历史记录中。
注意:在您最初使用 git-filter-branch 时,您是否使用了:
?
它可能已将标签保留在新历史记录中(不过我还没有测试过)
Look like the last step of this procedure described here
The idea is to read tags from the old versions of the repositories, to re-apply them on the new history.
Note: in your original use of git-filter-branch, did you use the:
?
It may have kept the tag in place on the new history (I have not tested it yet though)