diff --git a/Commands.md b/Commands.md index 2aec3ac92..ae0b97895 100644 --- a/Commands.md +++ b/Commands.md @@ -68,6 +68,7 @@ - [`git touch`](#git-touch) - [`git undo`](#git-undo) - [`git unlock`](#git-unlock) + - [`git utimes`](#git-utimes) ## git extras @@ -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 +``` diff --git a/bin/git-utimes b/bin/git-utimes new file mode 100755 index 000000000..abeeee7d8 --- /dev/null +++ b/bin/git-utimes @@ -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 + 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 diff --git a/etc/git-extras-completion.zsh b/etc/git-extras-completion.zsh index 702cc3949..fe7742ddb 100644 --- a/etc/git-extras-completion.zsh +++ b/etc/git-extras-completion.zsh @@ -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' diff --git a/man/git-extras.md b/man/git-extras.md index 8fa0424ec..bba0fcf37 100644 --- a/man/git-extras.md +++ b/man/git-extras.md @@ -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 diff --git a/man/git-utimes.1 b/man/git-utimes.1 new file mode 100644 index 000000000..f6d82bb6d --- /dev/null +++ b/man/git-utimes.1 @@ -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> diff --git a/man/git-utimes.html b/man/git-utimes.html new file mode 100644 index 000000000..2473e410d --- /dev/null +++ b/man/git-utimes.html @@ -0,0 +1,114 @@ + + + + + + git-utimes(1) - Change files modification time to their last commit date + + + + +
+ + + +
    +
  1. git-utimes(1)
  2. +
  3. Git Extras
  4. +
  5. git-utimes(1)
  6. +
+ +

NAME

+

+ git-utimes - 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 <vt@altlinux.org>, inspired by Stackexchange comments.

+ +

REPORTING BUGS

+ +

<https://github.com/tj/git-extras/issues>

+ +

SEE ALSO

+ +

<https://github.com/tj/git-extras>

+ + +
    +
  1. +
  2. September 2020
  3. +
  4. git-utimes(1)
  5. +
+ +
+ + diff --git a/man/git-utimes.md b/man/git-utimes.md new file mode 100644 index 000000000..5ad693a3e --- /dev/null +++ b/man/git-utimes.md @@ -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 <>, inspired by Stackexchange comments. + +## REPORTING BUGS + +<> + +## SEE ALSO + +<> diff --git a/man/index.txt b/man/index.txt index 2f1fae287..3f64308c2 100644 --- a/man/index.txt +++ b/man/index.txt @@ -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