Skip to content

Instantly share code, notes, and snippets.

@jasonsparc
Last active February 22, 2019 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonsparc/b0c7f64ecc30c1ae5ef40abe236fb806 to your computer and use it in GitHub Desktop.
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
#!/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
@jasonsparc
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment