Last active
July 22, 2020 08:12
-
-
Save shivanshs9/ad9fdc0889419a652983982329cb6ff3 to your computer and use it in GitHub Desktop.
Wraps 'git commit' command to override AuthorDate and CommitDate (if date is provided)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## Copyright 2020 Shivansh Saini<shivanshs9@gmail.com> | |
# Licensed under MIT | |
usage() { | |
cat << EOD | |
Usage: `basename $0` [options] [date] -- [commit args] | |
Available options: | |
-h, --help Display this help | |
Wraps 'git commit' command to override AuthorDate and CommitDate (if date is provided) | |
EOD | |
} | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-h | --help) | |
usage | |
exit | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
adate="$1" | |
shift | |
;; | |
esac | |
done | |
cmd="git commit" | |
git_args="" | |
if [ $# -gt 0 ]; then | |
git_args=$(printf "%q\n" "$@") | |
fi | |
if [[ -n "$adate" ]]; then | |
cmd="GIT_COMMITTER_DATE=\"$adate\" $cmd --date \"$adate\"" | |
fi | |
echo "Executing $cmd $git_args..." | |
eval $cmd $git_args |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To commit dated "Jul 1 10:10:10 2020 +0530", run:
git backcommit "Fri Jul 1 10:10:10 2020 +0530"
To provide commit-specific options, run: