我在存储库中有一堆提交。我想看到两次提交之间更改的文件列表-从SHA1到SHA2。

我应该使用什么命令?


当前回答

正如巧妙的机器人在回答中所说:

git diff --name-status [SHA1 [SHA2]]

我的例子:

git diff --name-status 78a09k12067c24d8f117886c4723ccf111af4997 
4b95d595812211553070046bf2ebd807c0862cca
M       views/layouts/default.ctp
M       webroot/css/theme.css
A       webroot/img/theme/logo.png

其他回答

git diff --name-only SHA1 SHA2

其中您只需要包含足够的SHA散列来识别提交。例如,您也可以这样做

git diff --name-only HEAD~10 HEAD~5

查看第十次最新提交和第五次最新(或大约)提交之间的差异。

git diff --name-status [SHA1 [SHA2]]

类似于--name,只是你得到一个简单的前缀,告诉你文件发生了什么(修改、删除、添加…)

git log --name-status --oneline [SHA1..SHA2]

类似,但提交列在提交消息之后,因此您可以看到文件何时更改。

如果您对某些文件/文件夹发生的情况感兴趣,可以在git日志版本中添加--<filename>[<filename>…]。如果您想查看一次提交发生了什么,请将其称为SHA1,然后执行git log--名称状态--单行[SHA1^..SHA1]

文件状态标志:

Flag Name Meaning
M modified File has been modified
C copy-edit File has been copied and modified
R rename-edit File has been renamed and modified
A added File has been added
D deleted File has been deleted
U unmerged File has conflicts after a merge

但是,如果看到文件在您的分支和它的共同祖先与另一个分支之间发生了更改(例如,origin/master):

git diff --name-only `git merge-base origin/master HEAD`

正如巧妙的机器人在回答中所说:

git diff --name-status [SHA1 [SHA2]]

我的例子:

git diff --name-status 78a09k12067c24d8f117886c4723ccf111af4997 
4b95d595812211553070046bf2ebd807c0862cca
M       views/layouts/default.ctp
M       webroot/css/theme.css
A       webroot/img/theme/logo.png

对于只需要关注Java文件的人来说,这是我的解决方案:

 git diff --name-status SHA1 SHA2 | grep '\.java$'