christoph ender's

blog

saturday the 3rd of august, 2024

migrating git tags through rebase

listing all tags with “source” timestamp

First, …

cd original_repository
git tag |
while read TAG
do
  git log -1 --format=format:"$TAG|%aD%n" $TAG
done > tags-by-timestamp

This will produce a list of tags along with their (commit) timestamps

v1.0|Wed, 17 Mar 2021 08:01:03 +0000
v1.1|Fri, 19 Mar 2021 10:14:00 +0000
v1.2|Sat, 20 Mar 2021 19:37:14 +0000
v1.3|Tue, 23 Mar 2021 14:22:18 +0000
list all “destination” commits with timestamp

From the rebased branch, we'll now create a list of all commits in the log and their timestamps:

cd rebased_repository
git log --format=format:"s/%aD/%H/" > time-to-hash-mapping.sed

This will produce a set of commands for sed:

s/Fri, 22 May 2020 21:18:32 +0000/08730982bbc7b68c22b06e788ad0db99bdd88b37/
s/Sun, 24 May 2020 19:17:50 +0000/f2bfe7ef9fa2b67ddb33f1e3dddcc7df3f4acfce/
s/Sun, 24 Sep 2020 18:47:52 +0000/9d71c54c13fac56d1a6502cb48bf0975b4b37e1a/
s/Sun, 24 Sep 2020 18:44:00 +0000/19131ce0ba879dd36c12b9b6e132d5a39d3fd349/

create tags in destination repository

sed -f time-to-hash-mapping.sed < tags-by-timestamp

sed 's/\(.*\)\|\(.*\)/git tag -a "\1" -m "\1" -s \2/'