-
Notifications
You must be signed in to change notification settings - Fork 3
/
change-git-commit-date.sh
executable file
·54 lines (45 loc) · 1.28 KB
/
change-git-commit-date.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
#
# Change the commit and/or author date of git commits.
#
# change-date [-f] commit-to-change [branch-to-rewrite [commit-date [author-date]]]
#
# If -f is supplied it is passed to "git filter-branch".
#
# If <branch-to-rewrite> is not provided or is empty HEAD will be used.
# Use "--all" or a space separated list (e.g. "master next") to rewrite
# multiple branches.
#
# Based on http://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit
force=''
if test "x$1" = "x-f"; then
force='-f'
shift
fi
die() {
printf '%s\n' "$@"
exit 128
}
targ="$(git rev-parse --verify "$1" 2>/dev/null)" || die "$1 is not a commit"
br="${2:-HEAD}"
TARG_COMMIT="$targ"
TARG_COMMIT_DATE="${3-}"
TARG_AUTHOR_DATE="${4-}"
export TARG_COMMIT TARG_COMMIT_DATE TARG_AUTHOR_DATE
if test -z "$TARG_COMMIT_DATE"; then
echo "Commit date not set."
exit 1
fi
filt='
if test "$GIT_COMMIT" = "$TARG_COMMIT"; then
GIT_COMMITTER_DATE="$TARG_COMMIT_DATE"
export GIT_COMMITTER_DATE
if test -n "$TARG_AUTHOR_DATE"; then
GIT_AUTHOR_DATE="$TARG_AUTHOR_DATE"
else
GIT_AUTHOR_DATE="$TARG_COMMIT_DATE"
fi
export GIT_AUTHOR_DATE
fi
'
git filter-branch $force --env-filter "$filt" -- $br