diff --git a/Commands.md b/Commands.md index 295f71ec..2196e0c2 100644 --- a/Commands.md +++ b/Commands.md @@ -1624,6 +1624,8 @@ $ git browse-ci upstream Change files modification time to their last commit date. Does not touch files that are in the working tree or index. +To also update the timestamps for directories, use the `--touch-dirs` or `-d` flag. + The `--newer` flag preserves the original modification time of files that were committed from the local repo, by only touching files that are newer than their last commit date. ```bash diff --git a/bin/git-utimes b/bin/git-utimes index f0dc1a4e..d26a2521 100755 --- a/bin/git-utimes +++ b/bin/git-utimes @@ -7,12 +7,28 @@ set -euo pipefail IFS=$'\n\t' -if [[ "${1:-}" == "--newer" ]]; then - op=le - shift -else - op=eq -fi +# %ct: committer date, UNIX timestamp / %at: author date, UNIX timestamp +# --diff-filter=d: exclude deleted files +log_opts=( + --format='%ct' + --diff-filter=d +) +op=eq + +for arg in "$@"; do + case "$arg" in + --newer) + op=le + ;; + --touch-dirs | -d) + log_opts+=(--dirstat=files,0) + ;; + *) + >&2 echo "unknown argument $arg found" + exit 1 + ;; + esac +done # BSD systems if date -j &>/dev/null; then @@ -33,8 +49,6 @@ if bash --help 2>&1 | grep -q -- '--norc'; then fi status_opts=(--porcelain --short) -# %ct: committer date, UNIX timestamp / %at: author date, UNIX timestamp -log_opts=(--format='%ct') if git status --help 2>&1 | grep -q -- "--no-renames"; then status_opts+=(--no-renames) log_opts+=(--no-renames) @@ -91,13 +105,17 @@ FILENAME==tmpfile { } # skip blank lines !/^$/ { - # skip deletes - if (substr($1, length($1), 1) ~ /D/) { - next - } if (NF == 1) { - ct=$1 - next + # dirstat line + if ($1 ~ /^.+% .+\/$/) { + # remove percentage before path + gsub(/^.+% /, "", $1) + $2 = $1 + # timestamp line + } else { + ct=$1 + next + } } $2 = substr($2, strip, length($2)- strip + 1) if ($2 in seen) { diff --git a/man/git-utimes.1 b/man/git-utimes.1 index f141002e..8addee61 100644 --- a/man/git-utimes.1 +++ b/man/git-utimes.1 @@ -1,6 +1,6 @@ -.\" generated with Ronn-NG/v0.9.1 -.\" http://github.com/apjanke/ronn-ng/tree/0.9.1 -.TH "GIT\-UTIMES" "1" "May 2022" "" "Git Extras" +.\" generated with Ronn-NG/v0.10.1 +.\" http://github.com/apjanke/ronn-ng/tree/0.10.1 +.TH "GIT\-UTIMES" "1" "April 2026" "" "Git Extras" .SH "NAME" \fBgit\-utimes\fR \- Change files modification time to their last commit date .SH "SYNOPSIS" @@ -11,6 +11,10 @@ Change files modification time to their last commit date\. Does not touch files \-\-newer .P Preserves the original modification time of files that were committed from the local repo, by only touching files that are newer than their last commit date\. +.P +\-\-touch\-dirs or \-d +.P +Also update the modification time of directories to the latest commit date of any file within them\. This can be useful for build systems that rely on directory timestamps\. .SH "EXAMPLES" Update all files' modification time to their last commit date, except those in working tree or index: .IP "" 4 @@ -25,6 +29,13 @@ As above, but preserve original modification time of files that were committed f $ git utimes \-\-newer .fi .IP "" 0 +.P +Update all files' and directories' modification time to their last commit date, except those in working tree or index: +.IP "" 4 +.nf +$ git utimes \-\-touch\-dirs +.fi +.IP "" 0 .SH "AUTHOR" Written by Vitaly Chikunov <\fIvt@altlinux\.org\fR>, inspired by Stackexchange comments\. Updated by Bill Wood <\fIwpwoodjr@gmail\.com\fR> to add \fB\-\-newer\fR flag and ignore files in the working tree or index\. .SH "REPORTING BUGS" diff --git a/man/git-utimes.html b/man/git-utimes.html index 9414dbc9..f9489da3 100644 --- a/man/git-utimes.html +++ b/man/git-utimes.html @@ -1,8 +1,8 @@
- - + +