gpt4 book ai didi

Git,重写主分支和相关标签的历史

转载 作者:太空狗 更新时间:2023-10-29 13:19:45 24 4
gpt4 key购买 nike

我刚刚第一次体验重写我的一个存储库的历史(使用 git-filter-branch)。问题是 repo 有几个标签,重写后似乎与结果历史完全断开。我认为这是因为与标签相关的历史没有被重写,所以它们必须指向旧的提交。那么,我该怎么做才能在新历史上“应用”标签。一点ASCII艺术,也许更容易理解我的问题:

原始 repo :

+  HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit

历史重写后 gitk --all 报告的 repo 结构:

    +  HEAD
|
|
|
|
|
|
|
|
+ Initial commit
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+ Initial commit

最佳答案

看起来像这个 procedure described here 的最后一步

$ git log --pretty=oneline origin/releases |
sed -n -e '/^\([0-9a-f]\{40\}\) Tag\( release\)\? \(.*\)/s--\3|\1|Tag release \3-p'
> ~/paludis-git-tags

$ while read name msg head ; do
git tag -m "${msg}" ${name} ${head} ;
done < paludis-git-tags

想法是从旧版本的存储库中读取标签,将它们重新应用到新的历史记录中。


注意:在你最初使用 git-filter-branch 时,你是否使用了:

-- --all

?

the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags.

它可能在新的历史记录中保留了标签(虽然我还没有测试过)

关于Git,重写主分支和相关标签的历史,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1138960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com