Git,重写主分支和相关标签的历史记录 [英] Git, rewriting history of master branch and associated tags

查看:125
本文介绍了Git,重写主分支和相关标签的历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了第一次重写我的回购协议(使用git-filter-branch)的历史。问题是,回购有几个标签,重写后似乎完全脱离了结果历史。我认为这是由于与标签相关的历史没有被重写,所以他们必须指向旧的提交。那么,我能做些什么来在新的历史上应用标签。一个小小的ASCII艺术,也许它更容易理解我的问题:

原始回购:

  + HEAD 
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+初始提交

gitk报告的回购结构 - all >

  + HEAD 
|
|
|
|
|
|
|
|
+初始提交
+ HEAD
|
|
+ TAG 0.2.0
|
|
+ TAG 0.1.0
|
|
+初始提交


解决方案

这里描述的这个程序的一步。

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

$ while read name msg head;做
git标签-m$ {msg}$ {name} $ {head};
完成< paludis-git-tags

这个想法是从老版本的仓库中读取标签, - 在新的历史记录上应用它们。






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

   -  --all 




- 将过滤分支选项与修订选项分开, - 全部可以重写所有分支和标签。

新的历史记录上的标签(尽管我还没有测试过)


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

解决方案

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:

-- --all

?

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

It may have kept the tag in place on the new history (I have not tested it yet though)

这篇关于Git,重写主分支和相关标签的历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆