Skip to content

Commit aa174b3

Browse files
committed
git-utimes: Change files modification time to their last commit date
Signed-off-by: Vitaly Chikunov <[email protected]>
1 parent a0a32ab commit aa174b3

File tree

8 files changed

+239
-1
lines changed

8 files changed

+239
-1
lines changed

Commands.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- [`git touch`](#git-touch)
6969
- [`git undo`](#git-undo)
7070
- [`git unlock`](#git-unlock)
71+
- [`git utimes`](#git-utimes)
7172

7273
## git extras
7374

@@ -1495,3 +1496,43 @@ Opens the current git repository website in your default web browser.
14951496
```bash
14961497
$ git browse
14971498
```
1499+
1500+
## git utimes
1501+
1502+
Change files modification time to their last commit date.
1503+
1504+
```bash
1505+
git-extras$ ls -l bin | head
1506+
total 308
1507+
-rwxr-xr-x 1 vt vt 489 Nov 8 13:56 git-alias
1508+
-rwxr-xr-x 1 vt vt 1043 Nov 8 13:56 git-archive-file
1509+
-rwxr-xr-x 1 vt vt 970 Nov 8 13:56 git-authors
1510+
-rwxr-xr-x 1 vt vt 267 Nov 8 13:56 git-back
1511+
-rwxr-xr-x 1 vt vt 899 Nov 8 13:56 git-browse
1512+
-rwxr-xr-x 1 vt vt 1932 Nov 8 13:56 git-brv
1513+
-rwxr-xr-x 1 vt vt 6282 Nov 8 13:56 git-bulk
1514+
-rwxr-xr-x 1 vt vt 18561 Nov 8 13:56 git-changelog
1515+
-rwxr-xr-x 1 vt vt 215 Nov 8 13:56 git-clear
1516+
git-extras$ git utimes
1517+
+ touch -d 2015-08-09T19:27:49+08:00 bin/git-alias
1518+
+ touch -d 2020-05-22T10:40:29+08:00 bin/git-archive-file
1519+
+ touch -d 2017-05-05T16:02:09+08:00 bin/git-authors
1520+
+ touch -d 2020-02-23T11:41:54+08:00 bin/git-back
1521+
+ touch -d 2020-06-23T09:31:21+10:00 bin/git-browse
1522+
+ touch -d 2020-01-15T10:46:19+01:00 bin/git-brv
1523+
+ touch -d 2019-12-21T13:35:59+08:00 bin/git-bulk
1524+
+ touch -d 2019-09-05T12:41:38+08:00 bin/git-changelog
1525+
+ touch -d 2016-11-19T16:41:19+00:00 bin/git-clear
1526+
[...]
1527+
git-extras$ ls -l bin | head
1528+
total 308
1529+
-rwxr-xr-x 1 vt vt 489 Aug 9 2015 git-alias
1530+
-rwxr-xr-x 1 vt vt 1043 May 22 05:40 git-archive-file
1531+
-rwxr-xr-x 1 vt vt 970 May 5 2017 git-authors
1532+
-rwxr-xr-x 1 vt vt 267 Feb 23 2020 git-back
1533+
-rwxr-xr-x 1 vt vt 899 Jun 23 02:31 git-browse
1534+
-rwxr-xr-x 1 vt vt 1932 Jan 15 2020 git-brv
1535+
-rwxr-xr-x 1 vt vt 6282 Dec 21 2019 git-bulk
1536+
-rwxr-xr-x 1 vt vt 18561 Sep 5 2019 git-changelog
1537+
-rwxr-xr-x 1 vt vt 215 Nov 19 2016 git-clear
1538+
```

bin/git-utimes

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Change files modification time to their last commit date
4+
#
5+
6+
if [ "$1" = --touch ]; then
7+
# Internal use option only just to parallelize things.
8+
shift
9+
for f; do
10+
t=$(git --no-pager log --no-renames --pretty=format:%cI -1 @ -- "$f" 2>/dev/null)
11+
if [ -n "$t" ]; then
12+
echo "+ touch -d $t $f" >&2
13+
touch -d "$t" "$f"
14+
fi
15+
done
16+
else
17+
# `-n` should be limited or parallelization will not give effect,
18+
# because all args will go into single worker.
19+
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
20+
git ls-tree -z -r -t --name-only @ \
21+
| xargs -0 -P${NPROC:-1} -n${NPROC:-1} -r git utimes --touch
22+
fi

etc/git-extras-completion.zsh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,5 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
400400
sync:'sync local branch with remote branch' \
401401
touch:'touch and add file to the index' \
402402
undo:'remove latest commits' \
403-
unlock:'unlock a file excluded from version control'
403+
unlock:'unlock a file excluded from version control' \
404+
utimes:'change files modification time to their last commit date'

man/git-extras.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ git-extras(1) -- Awesome GIT utilities
8888
- **git-touch(1)** Touch and add file to the index
8989
- **git-undo(1)** Remove latest commits
9090
- **git-unlock(1)** Unlock a file excluded from version control
91+
- **git-utimes(1)** Change files modification time to their last commit date
9192

9293
## AUTHOR
9394

man/git-utimes.1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-UTIMES" "1" "September 2020" "" "Git Extras"
5+
.
6+
.SH "NAME"
7+
\fBgit\-utimes\fR \- Change files modification time to their last commit date
8+
.
9+
.SH "SYNOPSIS"
10+
\fBgit\-utimes\fR
11+
.
12+
.SH "DESCRIPTION"
13+
Change files modification time to their last commit date\.
14+
.
15+
.SH "OPTIONS"
16+
No options needed\.
17+
.
18+
.SH "EXAMPLES"
19+
git utimes
20+
.
21+
.SH "AUTHOR"
22+
Written by Vitaly Chikunov <\fIvt@altlinux\.org\fR>, inspired by Stackexchange comments\.
23+
.
24+
.SH "REPORTING BUGS"
25+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
26+
.
27+
.SH "SEE ALSO"
28+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-utimes.html

Lines changed: 114 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-utimes.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
git-utimes(1) -- Change files modification time to their last commit date
2+
=========================================================================
3+
4+
## SYNOPSIS
5+
6+
`git-utimes`
7+
8+
## DESCRIPTION
9+
10+
Change files modification time to their last commit date.
11+
12+
## OPTIONS
13+
14+
No options needed.
15+
16+
## EXAMPLES
17+
18+
git utimes
19+
20+
## AUTHOR
21+
22+
Written by Vitaly Chikunov &lt;<[email protected]>&gt;, inspired by Stackexchange comments.
23+
24+
## REPORTING BUGS
25+
26+
&lt;<https://github.com/tj/git-extras/issues>&gt;
27+
28+
## SEE ALSO
29+
30+
&lt;<https://github.com/tj/git-extras>&gt;

man/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ git-sync(1) git-sync
6767
git-touch(1) git-touch
6868
git-undo(1) git-undo
6969
git-unlock(1) git-unlock
70+
git-utimes(1) git-utimes

0 commit comments

Comments
 (0)