Skip to content

Commit

Permalink
Useful script to backdate git tags
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Mar 27, 2024
1 parent ff2fd7d commit 60183d9
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions backdate-tags.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@echo off

REM Batch file to override the date and/or message of existing tag, or create a new
REM tag that takes the same date/time of an existing commit.
REM
REM Usage:
REM > backdate-tags.cmd v0.1.1 "New message"
REM
REM How it works:
REM * checkout the commit at the moment of the tag
REM * get the date/time of that commit and store in GIT_COMMITER_DATE env var
REM * recreate the tag (it will now take the date of its commit)
REM * push tags changes to remove (with --force)
REM * return to HEAD
REM
REM PS:
REM * these escape codes are for underlining the headers so they stand out between all GIT's output garbage
REM * the back-dating trick is taken from here: https://stackoverflow.com/questions/21738647/change-date-of-git-tag-or-github-release-based-on-it

ECHO.
ECHO List existing tags:
git tag -n

ECHO.
ECHO Checkout to tag:
git checkout tags/%1

REM Output the first string, containing the date of commit, and put it in a file
REM then set the contents of that file to env var GIT_COMMITTER_DATE (which in turn is needed to enable back-dating)
REM then delete the temp file
ECHO.
ECHO Retrieve original commit date

git show --format=%%aD | findstr "^[MTWFS][a-z][a-z],.*" > _date.tmp
< _date.tmp (set /p GIT_COMMITTER_DATE=)
del _date.tmp

ECHO Committer date for tag: %GIT_COMMITTER_DATE%
ECHO Overriding tag '%1' with text: %2
ECHO.
REM Override (with -af) the tag, if it exists (no quotes around %2)
git tag -af %1 -m %2

ECHO.
ECHO Updated tag:
git tag --points-at HEAD -n
ECHO.

REM Push to remove and override (with --force)
ECHO Push changes to remote
git push --tags --force

REM Go back to original HEAD
ECHO.
ECHO Back to original HEAD
git checkout -

ECHO.
ECHO List of all tags
git tag -n

0 comments on commit 60183d9

Please sign in to comment.