it-swarm.cn

Git显示过去2天内更改的文件

如何获得包含过去2天内更改的所有文件的列表?我知道

git log --name-status --since="2 days ago" 

但这会显示我的ID,日期和提交消息。我只需要更改的文件名列表。

用git可能吗?

57
dole doug
git log --pretty=format: --name-only --since="2 days ago"

如果某些文件在多次提交中重复,您可以使用管道对其进行过滤

git log --pretty=format: --name-only --since="2 days ago" | sort | uniq
83
Peng Qi
git diff --stat @{2.days.ago} # Deprecated!, see below

简短有效

编辑

TLDR:使用git diff $(git log -1 [email protected]{2.days.ago} --format=%H) --stat

很长的解释:原来的解决方案很好,但它有一点小故障,它只限于reflog,换句话说,只显示本地历史,因为reflog永远不会被推到 远程 。这就是为什么你在最近克隆的repos中获得warning: Log for 'master' only goes back to...的原因。

我在我的机器上配置了这个 别名

alias glasthour='git diff $(git log -1 [email protected]{last.hour} --format=%H) --stat' 
alias glastblock='git diff $(git log -1 [email protected]{4.hours.ago} --format=%H) --stat' 
alias glastday='git diff $(git log -1 [email protected]{last.day} --format=%H) --stat' 
alias glastweek='git diff $(git log -1 [email protected]{last.week} --format=%H) --shortstat | uniq' 
alias glastmonth='git diff $(git log -1 [email protected]{last.month} --format=%H) --shortstat | uniq'                                                                                                                

点数:@ adam-dymitruk回答如下

49
AA.

你可以做一个与2天前最接近的版本的差异:

git diff $(git log -1 --before="2 days ago" --format=%H).. --stat

--stat为您提供更改摘要。添加--name-only以排除任何元信息,并且只有文件名列表。

希望这可以帮助。

3
Adam Dymitruk

使用-raw选项来git log:

$ git log --raw --since=2.days

有关-raw格式中显示的标志的说明,请参阅git log帮助页面的--diff-filter部分。他们解释了每次提交中文件发生的情况:

   --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
       Select only files that are Added (A), Copied (C), Deleted (D),
       Modified (M), Renamed (R), have their type (i.e. regular file,
       symlink, submodule, ...) changed (T), are Unmerged (U), are Unknown
       (X), or have had their pairing Broken (B). Any combination of the
       filter characters (including none) can be used. When *
       (All-or-none) is added to the combination, all paths are selected
       if there is any file that matches other criteria in the comparison;
       if there is no file that matches other criteria, nothing is
       selected. 
3
holygeek
git log --pretty="format:" --since="2 days ago" --name-only
2
Stacey Richards