72

我怎样才能列出过去 2 天内更改的所有文件?我知道

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

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

用git可以吗?

4

5 回答 5

104
git log --pretty=format: --name-only --since="2 days ago"

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

git log --pretty=format: --name-only --since="2 days ago" | sort | uniq
于 2011-09-21T13:07:51.553 回答
58
git diff --stat @{2.days.ago} # Deprecated!, see below

简短而有效

编辑

TLDR:使用git diff $(git log -1 --before=@{2.days.ago} --format=%H) --stat

长解释:原来的解决方案很好,但它有一点小故障,它仅限于reflog,换句话说,只显示本地历史,因为reflog从来没有推送到远程。这就是您warning: Log for 'master' only goes back to...最近克隆了 in repos 的原因。

我已经在我的机器中配置了这个别名:

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

学分:@adam-dymitruk 在下面回答

于 2013-11-24T04:15:24.733 回答
3

使用 --raw 选项来 git log:

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

请参阅 git log 帮助页面的 --diff-filter 部分以了解以 --raw 格式显示的标志。他们解释了每次提交中的文件会发生什么:

   --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. 
于 2011-09-21T13:43:44.807 回答
3

您可以使用以下方法对最接近 2 天前的版本进行比较:

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

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

希望这可以帮助。

于 2011-09-21T18:02:49.803 回答
2
git log --pretty="format:" --since="2 days ago" --name-only
于 2011-09-21T12:52:53.303 回答