Last active
May 21, 2024 05:04
-
-
Save danieldownes/c31b2107879555ebcb436a4e10d2826a to your computer and use it in GitHub Desktop.
Commit file and use last modified date as author commit 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 | |
# Run directly from bash without download: | |
# curl -s https://gist.githubusercontent.com/danieldownes/c31b2107879555ebcb436a4e10d2826a/raw/ca495f5f28af778c72712472d279e27698c5606f/commitFilesByModificationDate.sh | bash | |
# Get list of all files in all folders and subfolders | |
# ignore file and '.git' folder | |
# Sort by modification date, desc | |
find . -type f \( ! -iname "Thumbs.db" \) ! -path "./.git/*" -printf "%TY-%Tm-%TdT%TH:%TM:%.2TS%Tz$%p\n" | | |
sort -n | | |
while read fname; | |
do | |
FD=$(echo "$fname" | cut -c 1-24) | |
FN=$(echo "$fname" | cut -f 2 -d$) | |
if git add "$FN" | |
then | |
git commit -m "$FN" | |
LC_ALL=C GIT_COMMITTER_DATE="$FD" git commit --amend --no-edit --date "$FD" --quiet | |
fi | |
done | |
# Commit any removed files between passes: | |
git commit -a -m "removed files" | |
LC_ALL=C GIT_COMMITTER_DATE="$FDD" git commit --amend --no-edit --date "$FDD" --quiet | |
# if lastDatetime <> thisDatetime | |
# git commit $FN -M "$FN $FD" | |
# $filesnames = "" | |
# Find all .dot files but ignore .htaccess file: | |
# $ find . -type f \( -iname ".*" ! -iname ".htaccess" \) | |
# -printf "%TY-%Tm-%Td %TH:%TM%Tz %p\n" -printf '%T@\t%p\n' | |
# Breakdown | |
: ' | |
find = list nodes recursively | |
. = from current directory | |
-type f = but only ones that are actually files | |
-printf = and print them in the following format | |
'%T@ = last modification time (in seconds, with fractions) | |
\t = then tab | |
%p = then file name | |
\n' = then newline | |
| sort -n = sort according to numerical value | |
| cut -f 2 = show only the second field | |
' | |
# Commit each file individually | |
# Set the commit and auther date to respective files last modification date | |
# Set commit and author date | |
#git commit --amend --date=2014-09-28T01:00:00+0000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment