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)
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!
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.
From this post