Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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). 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
like image 533
Ionuț G. Stan Avatar asked Jul 16 '09 17:07

Ionuț G. Stan


2 Answers

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)

like image 64
VonC Avatar answered Nov 14 '22 21:11

VonC


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!

like image 36
Jakub Narębski Avatar answered Nov 14 '22 20:11

Jakub Narębski