Skip to content

Instantly share code, notes, and snippets.

@jswrenn
Last active November 11, 2016 17:04
Show Gist options
  • Save jswrenn/a26f421eb3f548a679872d8969395393 to your computer and use it in GitHub Desktop.
Save jswrenn/a26f421eb3f548a679872d8969395393 to your computer and use it in GitHub Desktop.
Commit each file in the current working directory using its time of last modification.
git ls-files -z --others --exclude-standard \
| xargs -0 -I{} stat -c "%Y %n" "{}" \
| sort \
| cut -d' ' -f 2- \
| while read -r name; do
DATE=$(stat -c "%y" "$name")
git add "$name"
export GIT_AUTHOR_DATE="$DATE"
export GIT_COMMITTER_DATE="$DATE"
git commit -m "$name";
done
git ls-files -z --modified --exclude-standard \
| xargs -0 -I{} stat -c "%Y %n" "{}" \
| sort \
| cut -d' ' -f 2- \
| while read -r name; do
DATE=$(stat -c "%y" "$name")
git add "$name"
export GIT_AUTHOR_DATE="$DATE"
export GIT_COMMITTER_DATE="$DATE"
git commit -m "Updated $name";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment