Last active
February 22, 2019 13:33
-
-
Save jasonsparc/b0c7f64ecc30c1ae5ef40abe236fb806 to your computer and use it in GitHub Desktop.
`git-cheat-date` – A custom git command for conveniently updating both the committer date and the author date
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
#!/bin/bash | |
# Usage: git cheat-date | |
git rev-parse || exit $? | |
if [[ $1 == "-q" ]]; then | |
if_quiet="-q"; shift | |
else | |
echo "Replacing committer date..." | |
fi | |
# Stash if the index contains uncommitted changes. | |
if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then | |
git stash $if_quiet | |
did_stash=1 | |
fi | |
export GIT_COMMITTER_DATE="$([[ $1 ]] && echo "${!#}" || git log -1 --date="iso" --format="%ad")" | |
git commit $if_quiet --amend --no-edit --date="$GIT_COMMITTER_DATE" | |
if [[ $did_stash = 1 ]]; then | |
git stash pop --index $if_quiet | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also, https://gist.github.com/jasonsparc/736ef0e0bcac7025addf8a4ac3e1cc16