Skip to content
Merged
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
41 changes: 41 additions & 0 deletions Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
- [`git touch`](#git-touch)
- [`git undo`](#git-undo)
- [`git unlock`](#git-unlock)
- [`git utimes`](#git-utimes)

## git extras

Expand Down Expand Up @@ -1495,3 +1496,43 @@ Opens the current git repository website in your default web browser.
```bash
$ git browse
```

## git utimes

Change files modification time to their last commit date.

```bash
git-extras$ ls -l bin | head
total 308
-rwxr-xr-x 1 vt vt 489 Nov 8 13:56 git-alias
-rwxr-xr-x 1 vt vt 1043 Nov 8 13:56 git-archive-file
-rwxr-xr-x 1 vt vt 970 Nov 8 13:56 git-authors
-rwxr-xr-x 1 vt vt 267 Nov 8 13:56 git-back
-rwxr-xr-x 1 vt vt 899 Nov 8 13:56 git-browse
-rwxr-xr-x 1 vt vt 1932 Nov 8 13:56 git-brv
-rwxr-xr-x 1 vt vt 6282 Nov 8 13:56 git-bulk
-rwxr-xr-x 1 vt vt 18561 Nov 8 13:56 git-changelog
-rwxr-xr-x 1 vt vt 215 Nov 8 13:56 git-clear
git-extras$ git utimes
+ touch -d 2015-08-09T19:27:49+08:00 bin/git-alias
+ touch -d 2020-05-22T10:40:29+08:00 bin/git-archive-file
+ touch -d 2017-05-05T16:02:09+08:00 bin/git-authors
+ touch -d 2020-02-23T11:41:54+08:00 bin/git-back
+ touch -d 2020-06-23T09:31:21+10:00 bin/git-browse
+ touch -d 2020-01-15T10:46:19+01:00 bin/git-brv
+ touch -d 2019-12-21T13:35:59+08:00 bin/git-bulk
+ touch -d 2019-09-05T12:41:38+08:00 bin/git-changelog
+ touch -d 2016-11-19T16:41:19+00:00 bin/git-clear
[...]
git-extras$ ls -l bin | head
total 308
-rwxr-xr-x 1 vt vt 489 Aug 9 2015 git-alias
-rwxr-xr-x 1 vt vt 1043 May 22 05:40 git-archive-file
-rwxr-xr-x 1 vt vt 970 May 5 2017 git-authors
-rwxr-xr-x 1 vt vt 267 Feb 23 2020 git-back
-rwxr-xr-x 1 vt vt 899 Jun 23 02:31 git-browse
-rwxr-xr-x 1 vt vt 1932 Jan 15 2020 git-brv
-rwxr-xr-x 1 vt vt 6282 Dec 21 2019 git-bulk
-rwxr-xr-x 1 vt vt 18561 Sep 5 2019 git-changelog
-rwxr-xr-x 1 vt vt 215 Nov 19 2016 git-clear
```
22 changes: 22 additions & 0 deletions bin/git-utimes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# Change files modification time to their last commit date
#

if [ "$1" = --touch ]; then
# Internal use option only just to parallelize things.
shift
for f; do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for is to support multiple arguments. Why not? This should reduce number of execs. Are you against of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correction: s/execs/forks/

Copy link
Collaborator

Choose a reason for hiding this comment

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

@vt-alt
I got it, it is OK.

t=$(git --no-pager log --no-renames --pretty=format:%cI -1 @ -- "$f" 2>/dev/null)
if [ -n "$t" ]; then
echo "+ touch -d $t $f" >&2
touch -d "$t" "$f"
fi
done
else
# `-n` should be limited or parallelization will not give effect,
# because all args will go into single worker.
NPROC=$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
git ls-tree -z -r -t --name-only @ \
| xargs -0 -P${NPROC:-1} -n${NPROC:-1} -r git utimes --touch
fi
3 changes: 2 additions & 1 deletion etc/git-extras-completion.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,5 @@ zstyle ':completion:*:*:git:*' user-commands $existing_user_commands \
sync:'sync local branch with remote branch' \
touch:'touch and add file to the index' \
undo:'remove latest commits' \
unlock:'unlock a file excluded from version control'
unlock:'unlock a file excluded from version control' \
utimes:'change files modification time to their last commit date'
1 change: 1 addition & 0 deletions man/git-extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ git-extras(1) -- Awesome GIT utilities
- **git-touch(1)** Touch and add file to the index
- **git-undo(1)** Remove latest commits
- **git-unlock(1)** Unlock a file excluded from version control
- **git-utimes(1)** Change files modification time to their last commit date

## AUTHOR

Expand Down
28 changes: 28 additions & 0 deletions man/git-utimes.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-UTIMES" "1" "September 2020" "" "Git Extras"
.
.SH "NAME"
\fBgit\-utimes\fR \- Change files modification time to their last commit date
.
.SH "SYNOPSIS"
\fBgit\-utimes\fR
.
.SH "DESCRIPTION"
Change files modification time to their last commit date\.
.
.SH "OPTIONS"
No options needed\.
.
.SH "EXAMPLES"
git utimes
.
.SH "AUTHOR"
Written by Vitaly Chikunov <\fIvt@altlinux\.org\fR>, inspired by Stackexchange comments\.
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
114 changes: 114 additions & 0 deletions man/git-utimes.html

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

30 changes: 30 additions & 0 deletions man/git-utimes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
git-utimes(1) -- Change files modification time to their last commit date
=========================================================================

## SYNOPSIS

`git-utimes`

## DESCRIPTION

Change files modification time to their last commit date.

## OPTIONS

No options needed.

## EXAMPLES

git utimes

## AUTHOR

Written by Vitaly Chikunov &lt;<[email protected]>&gt;, inspired by Stackexchange comments.

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;
1 change: 1 addition & 0 deletions man/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ git-sync(1) git-sync
git-touch(1) git-touch
git-undo(1) git-undo
git-unlock(1) git-unlock
git-utimes(1) git-utimes