Git, rewriting history of master branch and associated tags
Asked Answered
O

3

5

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
Oxymoron answered 16/7, 2009 at 17:6 Comment(0)
C
5

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)

Cid answered 16/7, 2009 at 17:47 Comment(1)
Thanks VonC, I missed the -- --all part. Luckily I had a backup of the repository and tried again with the --all option and it worked as I wished.Maternity
C
2

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!

Catima answered 16/7, 2009 at 20:17 Comment(1)
Thanks Jakub, I didn't know about annotated and signed tags. Useful info. Thanks again.Maternity
A
1

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.

enter image description here

From this post

Autocrat answered 14/8, 2017 at 21:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.