我如何打印一份包含所有提交文件的简单列表?
尽管下面列出了这些文件,但它也包含了每个文件不需要的差异信息:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
我如何打印一份包含所有提交文件的简单列表?
尽管下面列出了这些文件,但它也包含了每个文件不需要的差异信息:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
当前回答
我经常使用更改后的别名。要设置它,请执行以下操作:
git config --global alias.changed 'show --pretty="format:" --name-only'
然后:
git changed (lists files modified in last commit)
git changed bAda55 (lists files modified in this commit)
git changed bAda55..ff0021 (lists files modified between those commits)
可能有用的类似命令:
git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
git show --name-only
其他回答
如果要获取已更改文件的列表:
git diff-tree --no-commit-id --name-only -r <commit-ish>
如果要获取提交中所有文件的列表,可以使用
git ls-tree --name-only -r <commit-ish>
有一个简单的技巧可以作为文件列表查看。只需在哈希之后添加:
git show 9d3a52c474:
然后你可以钻进去,
git show 9d3a52c474:someDir/someOtherDir
如果你点击一个文件,你会得到该文件的原始版本;如果你只是在寻找一个好的参考或关键的代码片段(差异可能会使一切变得一团糟),
git show 9d3a52c474:someDir/someOtherDir/somefile
这种方法的唯一缺点是它不容易显示文件树。
还有gitwhatchanged,它比gitlog更低级
NAME
git-whatchanged - Show logs with difference each commit introduces
它输出提交摘要,其中包含其下的文件列表及其模式,以及它们是否被添加(a)、删除(D)或修改(M);
$ git whatchanged f31a441398fb7834fde24c5b0c2974182a431363
会给出如下内容:
commit f31a441398fb7834fde24c5b0c2974182a431363
Author: xx <xx@xx.nl>
Date: Tue Sep 29 17:23:22 2015 +0200
added fb skd and XLForm
:000000 100644 0000000... 90a20d7... A Pods/Bolts/Bolts/Common/BFCancellationToken.h
:000000 100644 0000000... b5006d0... A Pods/Bolts/Bolts/Common/BFCancellationToken.m
:000000 100644 0000000... 3e7b711... A Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.h
:000000 100644 0000000... 9c8a7ae... A Pods/Bolts/Bolts/Common/BFCancellationTokenRegistration.m
:000000 100644 0000000... bd6e7a1... A Pods/Bolts/Bolts/Common/BFCancellationTokenSource.h
:000000 100644 0000000... 947f725... A Pods/Bolts/Bolts/Common/BFCancellationTokenSource.m
:000000 100644 0000000... cf7dcdf... A Pods/Bolts/Bolts/Common/BFDefines.h
:000000 100644 0000000... 02af9ba... A Pods/Bolts/Bolts/Common/BFExecutor.h
:000000 100644 0000000... 292e27c... A Pods/Bolts/Bolts/Common/BFExecutor.m
:000000 100644 0000000... 827071d... A Pods/Bolts/Bolts/Common/BFTask.h
...
我知道这个答案并不符合“没有无关信息”,但我仍然认为这个列表比文件名更有用。
$ git log 88ee8^..88ee8 --name-only --pretty="format:"
我使用此命令在合并提交中获取已更改文件的列表
λ git log -m -1 --name-only --pretty="format:"
configs/anotherconfig.xml
configs/configsInRepo.xml
or
λ git log -m -1 --name-status --pretty="format:"
A configs/anotherconfig.xml
M configs/configsInRepo.xml