Skip to content

Commit e76f921

Browse files
authored
Merge pull request #248 from fsprojects/useful-git-script
Useful script to backdate git tags
2 parents ff2fd7d + 60183d9 commit e76f921

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

backdate-tags.cmd

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 List existing tags:
22+
git tag -n
23+
24+
ECHO.
25+
ECHO Checkout to tag:
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 Retrieve original commit date
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 Updated tag:
46+
git tag --points-at HEAD -n
47+
ECHO.
48+
49+
REM Push to remove and override (with --force)
50+
ECHO Push changes to remote
51+
git push --tags --force
52+
53+
REM Go back to original HEAD
54+
ECHO.
55+
ECHO Back to original HEAD
56+
git checkout -
57+
58+
ECHO.
59+
ECHO List of all tags
60+
git tag -n

0 commit comments

Comments
 (0)