|
| 1 | +@echo off |
| 2 | + |
| 3 | +REM Batch file to override the date and/or message of existing tag, or create a new |
| 4 | +REM tag that takes the same date/time of an existing commit. |
| 5 | +REM |
| 6 | +REM Usage: |
| 7 | +REM > backdate-tags.cmd v0.1.1 "New message" |
| 8 | +REM |
| 9 | +REM How it works: |
| 10 | +REM * checkout the commit at the moment of the tag |
| 11 | +REM * get the date/time of that commit and store in GIT_COMMITER_DATE env var |
| 12 | +REM * recreate the tag (it will now take the date of its commit) |
| 13 | +REM * push tags changes to remove (with --force) |
| 14 | +REM * return to HEAD |
| 15 | +REM |
| 16 | +REM PS: |
| 17 | +REM * these escape codes are for underlining the headers so they stand out between all GIT's output garbage |
| 18 | +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 |
| 19 | + |
| 20 | +ECHO. |
| 21 | +ECHO [4;97mList existing tags:[0m |
| 22 | +git tag -n |
| 23 | + |
| 24 | +ECHO. |
| 25 | +ECHO [4;97mCheckout to tag:[0m |
| 26 | +git checkout tags/%1 |
| 27 | + |
| 28 | +REM Output the first string, containing the date of commit, and put it in a file |
| 29 | +REM then set the contents of that file to env var GIT_COMMITTER_DATE (which in turn is needed to enable back-dating) |
| 30 | +REM then delete the temp file |
| 31 | +ECHO. |
| 32 | +ECHO [4;97mRetrieve original commit date[0m |
| 33 | + |
| 34 | +git show --format=%%aD | findstr "^[MTWFS][a-z][a-z],.*" > _date.tmp |
| 35 | +< _date.tmp (set /p GIT_COMMITTER_DATE=) |
| 36 | +del _date.tmp |
| 37 | + |
| 38 | +ECHO Committer date for tag: %GIT_COMMITTER_DATE% |
| 39 | +ECHO Overriding tag '%1' with text: %2 |
| 40 | +ECHO. |
| 41 | +REM Override (with -af) the tag, if it exists (no quotes around %2) |
| 42 | +git tag -af %1 -m %2 |
| 43 | + |
| 44 | +ECHO. |
| 45 | +ECHO [4;97mUpdated tag:[0m |
| 46 | +git tag --points-at HEAD -n |
| 47 | +ECHO. |
| 48 | + |
| 49 | +REM Push to remove and override (with --force) |
| 50 | +ECHO [4;97mPush changes to remote[0m |
| 51 | +git push --tags --force |
| 52 | + |
| 53 | +REM Go back to original HEAD |
| 54 | +ECHO. |
| 55 | +ECHO [4;97mBack to original HEAD[0m |
| 56 | +git checkout - |
| 57 | + |
| 58 | +ECHO. |
| 59 | +ECHO [4;97mList of all tags[0m |
| 60 | +git tag -n |
0 commit comments