After converting all of my lightweight tags to annotated ones, I noticed that the dates were all out of order. I decided that I wanted the tags to have the same dates as the respective commits, so I wrote a script to do that based on this StackOverflow answer:
#!/bin/bash
for tag in `git tag`; do
date="$(git show $tag^0 -s --format=%aD)"
GIT_COMMITTER_DATE="$date" git tag -a -f $tag $tag^0
done
The original answer didn’t work, because git show $tag --format=%aD
still shows the annotated tag information before showing the commit information. I noticed that a comment on another answer suggested that adding ^0
to the tag reference would reference the commit instead of the tag, so I tried that to remove the annotated information and it worked!
However, git still opened my editor for each tag to edit the contents of the annotated tag, so I had to quit the editor for each tag. There doesn’t seem to be a --no-edit
tag in the help, like there is for commit --amend
, so I’m not sure if there’s a way around this.
After the tags had been updated, git push --tags --force
pushed the updated tags to the remote.