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

时间:2011-09-21 12:44:25

标签: git file logging git-log fileupdate

如何列出过去2天内更改过的所有文件?我知道

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

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

git可以吗?

5 个答案:

答案 0 :(得分:83)

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

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

git log --pretty=format: --name-only --since="2 days ago" | sort | uniq

答案 1 :(得分:50)

git diff --stat @{2.days.ago} # Deprecated!, see below

简短有效

修改

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

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

我已在我的机器中配置了别名

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在下面回答

答案 2 :(得分:3)

使用-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 :(得分:3)

您可以使用以下内容进行与2天前最接近的版本的差异:

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

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

希望这有帮助。

答案 4 :(得分:2)

git log --pretty="format:" --since="2 days ago" --name-only
相关问题