Git 显示最近 2 天内更改的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7499938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:53:24  来源:igfitidea点击:

Git show files that were changed in the last 2 days

gitfilelogginggit-logfileupdate

提问by dole doug

How can I have a list with all the files that were changed in the last 2 days? I know about

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

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

but this will show me ids, dates and commit messages. All I need is the list of the file names which were changed.

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

Is that possible with git?

用git可以吗?

回答by Peng Qi

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

if some files duplicate in multiple commits, you can use pipe to filter it

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

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

回答by AA.

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

Short and effective

简短有效

Edit

编辑

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

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

Long explanation: The original solution was good, but it had a little glitch, it was limited to the reflog, in other words, only shows the local history, because reflogis never pushed to remote. This is the reason why you get the warning: Log for 'master' only goes back to...in repos recently cloned.

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

I have configured this aliasin my machine:

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

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'                                                                                                                

credits: answer below by @adam-dymitruk

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

回答by holygeek

Use the --raw option to git log:

使用 --raw 选项来 git log:

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

See the --diff-filter part of the git log help page for the explanation of the flags shown in the --raw format. They explain what happen to the files in each commit:

有关以 --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. 

回答by Adam Dymitruk

You can do a diff of a version that's closest to 2 days ago with:

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

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

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

--statgives you a summary of changes. Add --name-onlyto exclude any meta information and have only a file name listing.

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

Hope this helps.

希望这可以帮助。

回答by Stacey Richards

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