简体   繁体   English

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

[英]Git, rewriting history of master branch and associated tags

I've just had my first experience with rewriting the history of one of my repos (using git-filter-branch). 我刚刚第一次重写了我的一个repos的历史(使用git-filter-branch)。 The problem is that the repo had several tags, which after rewriting seem to be completely disconnected from the resulted history. 问题是repo有几个标签,重写之后似乎与结果历史完全断开。 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: 一点点ASCII艺术,也许更容易理解我的问题:

Original repo: 原始回购:

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

Repo structure reported by gitk --all after history rewrite: gitk --all报告的回购结构 - 历史重写后的所有结构:

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

Look like the last step of this 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

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: 注意:在你最初使用的git-filter-branch中,你使用了:

-- --all

?

the -- that separates filter-branch options from revision options, and the --all to rewrite all branches and tags. --将过滤器分支选项与修订选项分开, -- --all重写所有分支和标签。

It may have kept the tag in place on the new history (I have not tested it yet though) 它可能已将标记保留在新历史记录中(我还没有测试过它)

First, you have to rewrite tags too , eg (as VonC said ) by using --all option to rewrite all references. 首先,你必须重写标签 ,例如(如VonC所说 ),使用--all选项重写所有引用。

If you have annotated tags (heavyweight tags) you have also to use --tag-name-filter option, eg as --tag-name-filter cat . 如果您有注释标签 (重量级标签),您还必须使用--tag-name-filter选项,例如--tag-name-filter cat Note that you cannot rewrite signed tags! 请注意,您无法重写签名标签!

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. 如果要执行可以使用git filter-branch完成的更改,则可以使用--tag-name-filter ,如上所述。

If you want to do interactive rebasing though, you need something else. 如果你想进行交互式变基,你还需要其他东西。

Both things can be accomplished with git rebasetags 这两件事都可以使用git rebasetags完成

In case the rebase is interactive, you will be presented with a bash shell where you can make the changes. 如果rebase是交互式的,您将看到一个bash shell,您可以在其中进行更改。 Upon exiting that shell, the tags will be restored. 退出该shell后,将恢复标记。

在此输入图像描述

From this post 这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM