Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 32 additions & 14 deletions bin/git-utimes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -91,13 +105,17 @@ FILENAME==tmpfile {
}
# skip blank lines
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update this comment

!/^$/ {
# 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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When calling in a suddir, will a path be stripped twice? One in here, another in line 120

$2 = $1
# timestamp line
} else {
ct=$1
next
}
}
$2 = substr($2, strip, length($2)- strip + 1)
if ($2 in seen) {
Expand Down
17 changes: 14 additions & 3 deletions man/git-utimes.1
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand Down
15 changes: 12 additions & 3 deletions man/git-utimes.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions man/git-utimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ git-utimes(1) -- Change files modification time to their last commit date
--newer

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.

--touch-dirs or -d

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.

## EXAMPLES

Expand All @@ -24,6 +28,10 @@ Update all files' modification time to their last commit date, except those in w
As above, but preserve original modification time of files that were committed from local repo:

$ git utimes --newer

Update all files' and directories' modification time to their last commit date, except those in working tree or index:

$ git utimes --touch-dirs

## AUTHOR

Expand Down
Loading