Merge pull request #882 from vt-alt/git-utimes

git-utimes: Change files modification time to their last commit date
This commit is contained in:
罗泽轩 2020-11-29 11:40:12 +08:00 committed by GitHub
commit e6caa931a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 239 additions and 1 deletions

View file

@ -67,6 +67,7 @@
- [`git touch`](#git-touch)
- [`git undo`](#git-undo)
- [`git unlock`](#git-unlock)
- [`git utimes`](#git-utimes)
## git extras
@ -1490,3 +1491,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
bin/git-utimes Executable file
View file

@ -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

View file

@ -397,4 +397,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'

View file

@ -93,6 +93,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

28
man/git-utimes.1 Normal file
View file

@ -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
man/git-utimes.html Normal file
View file

@ -0,0 +1,114 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='content-type' value='text/html;charset=utf8'>
<meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
<title>git-utimes(1) - Change files modification time to their last commit date</title>
<style type='text/css' media='all'>
/* style: man */
body#manpage {margin:0}
.mp {max-width:100ex;padding:0 9ex 1ex 4ex}
.mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
.mp h2 {margin:10px 0 0 0}
.mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
.mp h3 {margin:0 0 0 4ex}
.mp dt {margin:0;clear:left}
.mp dt.flush {float:left;width:8ex}
.mp dd {margin:0 0 0 9ex}
.mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
.mp pre {margin-bottom:20px}
.mp pre+h2,.mp pre+h3 {margin-top:22px}
.mp h2+pre,.mp h3+pre {margin-top:5px}
.mp img {display:block;margin:auto}
.mp h1.man-title {display:none}
.mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
.mp h2 {font-size:16px;line-height:1.25}
.mp h1 {font-size:20px;line-height:2}
.mp {text-align:justify;background:#fff}
.mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
.mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
.mp u {text-decoration:underline}
.mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
.mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
.mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
.mp b.man-ref {font-weight:normal;color:#434241}
.mp pre {padding:0 4ex}
.mp pre code {font-weight:normal;color:#434241}
.mp h2+pre,h3+pre {padding-left:0}
ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
ol.man-decor {width:100%}
ol.man-decor li.tl {text-align:left}
ol.man-decor li.tc {text-align:center;letter-spacing:4px}
ol.man-decor li.tr {text-align:right;float:right}
</style>
</head>
<!--
The following styles are deprecated and will be removed at some point:
div#man, div#man ol.man, div#man ol.head, div#man ol.man.
The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
.man-navigation should be used instead.
-->
<body id='manpage'>
<div class='mp' id='man'>
<div class='man-navigation' style='display:none'>
<a href="#NAME">NAME</a>
<a href="#SYNOPSIS">SYNOPSIS</a>
<a href="#DESCRIPTION">DESCRIPTION</a>
<a href="#OPTIONS">OPTIONS</a>
<a href="#EXAMPLES">EXAMPLES</a>
<a href="#AUTHOR">AUTHOR</a>
<a href="#REPORTING-BUGS">REPORTING BUGS</a>
<a href="#SEE-ALSO">SEE ALSO</a>
</div>
<ol class='man-decor man-head man head'>
<li class='tl'>git-utimes(1)</li>
<li class='tc'>Git Extras</li>
<li class='tr'>git-utimes(1)</li>
</ol>
<h2 id="NAME">NAME</h2>
<p class="man-name">
<code>git-utimes</code> - <span class="man-whatis">Change files modification time to their last commit date</span>
</p>
<h2 id="SYNOPSIS">SYNOPSIS</h2>
<p><code>git-utimes</code></p>
<h2 id="DESCRIPTION">DESCRIPTION</h2>
<p> Change files modification time to their last commit date.</p>
<h2 id="OPTIONS">OPTIONS</h2>
<p> No options needed.</p>
<h2 id="EXAMPLES">EXAMPLES</h2>
<p> git utimes</p>
<h2 id="AUTHOR">AUTHOR</h2>
<p>Written by Vitaly Chikunov &lt;<a href="&#x6d;&#x61;&#x69;&#108;&#116;&#111;&#x3a;&#118;&#x74;&#64;&#97;&#x6c;&#x74;&#x6c;&#105;&#x6e;&#117;&#120;&#46;&#x6f;&#114;&#x67;" data-bare-link="true">&#118;&#x74;&#64;&#97;&#x6c;&#x74;&#x6c;&#x69;&#110;&#117;&#120;&#x2e;&#x6f;&#114;&#103;</a>&gt;, inspired by Stackexchange comments.</p>
<h2 id="REPORTING-BUGS">REPORTING BUGS</h2>
<p>&lt;<a href="https://github.com/tj/git-extras/issues" data-bare-link="true">https://github.com/tj/git-extras/issues</a>&gt;</p>
<h2 id="SEE-ALSO">SEE ALSO</h2>
<p>&lt;<a href="https://github.com/tj/git-extras" data-bare-link="true">https://github.com/tj/git-extras</a>&gt;</p>
<ol class='man-decor man-foot man foot'>
<li class='tl'></li>
<li class='tc'>September 2020</li>
<li class='tr'>git-utimes(1)</li>
</ol>
</div>
</body>
</html>

30
man/git-utimes.md Normal file
View file

@ -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;<vt@altlinux.org>&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;

View file

@ -66,3 +66,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