如何创建一个包含最近两天内所有被修改文件的列表?我知道相关命令是:
git log --name-status --since="2 days ago"
但是这将向我显示标识、日期和提交消息。我需要的只是被修改的文件名列表。
Git能做到这一点吗?
如何创建一个包含最近两天内所有被修改文件的列表?我知道相关命令是:
git log --name-status --since="2 days ago"
但是这将向我显示标识、日期和提交消息。我需要的只是被修改的文件名列表。
Git能做到这一点吗?
git log --pretty=format: --name-only --since="2 days ago"
如果同一些文件在多个提交中重复出现,你可以使用管道符过滤它们。
git log --pretty=format: --name-only --since="2 days ago" | sort | uniq
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...
的原因。
我已经在我的机器上配置了这个别名:
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
git diff --stat "@{2 days ago}"
,才能使其正常工作。(可能是因为我在Windows上) - Annabel.../
前缀,可能会破坏输出。 - galmok-1 --before
而不是--after
吗? - ConorSheehan1使用 --raw 选项来查看 git log:
$ git log --raw --since=2.days
--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.
您可以使用以下命令对最接近两天前的版本进行差异比较:
git diff $(git log -1 --before="2 days ago" --format=%H).. --stat
--stat
选项可提供更改摘要。添加--name-only
选项可排除任何元信息并仅列出文件名。
希望这能有所帮助。
git log --pretty="format:" --since="2 days ago" --name-only
git diff --stat @{2.days.ago}
更短更简洁。 - Joshua Dancegit diff --stat @{2.days.ago}
不显示完整路径,对于长路径和多项目,路径可能重叠,导致输出无法使用。 - galmok