git 如何仅列出两次提交之间更改的文件名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1552340/
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
How to list only the file names that changed between two commits?
提问by Shawn
I have a bunch of commits in the repo. I want to see a list of files changed between two commits - from SHA1 to SHA2.
我在回购中有一堆提交。我想查看在两次提交之间更改的文件列表 - 从 SHA1 到 SHA2。
What command should I use?
我应该使用什么命令?
回答by Peter
git diff --name-only SHA1 SHA2
where you only need to include enough of the SHA to identify the commits. You can also do, for example
您只需要包含足够的 SHA 来识别提交。你也可以做,例如
git diff --name-only HEAD~10 HEAD~5
to see the differences between the tenth latest commit and the fifth latest (or so).
查看第十次最新提交和第五次最新提交(左右)之间的差异。
回答by artfulrobot
git diff --name-status [SHA1 [SHA2]]
is like --name-only, except you get a simple prefix telling you what happened to the file (modified, deleted, added...)
就像--name-only,除了你得到一个简单的前缀,告诉你文件发生了什么(修改,删除,添加......)
git log --name-status --oneline [SHA1..SHA2]
is similar, but commits are listed after the commit message, so you can see when a file was changed.
类似,但提交列在提交消息之后,因此您可以查看文件何时更改。
if you're interested in just what happened to certain files/folders you can append
-- <filename> [<filename>...]
to thegit log
version.if you want to see what happened for a single commit, call it SHA1, then do
git log --name-status --oneline [SHA1^..SHA1]
如果您对某些文件/文件夹发生了什么感兴趣,您可以附加
-- <filename> [<filename>...]
到git log
版本中。如果您想查看单个提交发生了什么,请将其称为 SHA1,然后执行
git log --name-status --oneline [SHA1^..SHA1]
File status flags:
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
文件状态标志:
M 已修改 - 文件已被修改
C 复制编辑 - 文件已被复制和修改
R 重命名 - 编辑 - 文件已被重命名和修改
A 添加 - 文件已添加
D 删除 - 文件已删除
U 未合并 -合并后文件有冲突
回答by leeyuiwah
It seems that no one has mentioned the switch --stat
:
似乎没有人提到过开关--stat
:
$ git diff --stat HEAD~5 HEAD
.../java/org/apache/calcite/rex/RexSimplify.java | 50 +++++++++++++++++-----
.../apache/calcite/sql/fun/SqlTrimFunction.java | 2 +-
.../apache/calcite/sql2rel/SqlToRelConverter.java | 16 +++++++
.../org/apache/calcite/util/SaffronProperties.java | 19 ++++----
.../org/apache/calcite/test/RexProgramTest.java | 24 +++++++++++
.../apache/calcite/test/SqlToRelConverterTest.java | 8 ++++
.../apache/calcite/test/SqlToRelConverterTest.xml | 15 +++++++
pom.xml | 2 +-
.../apache/calcite/adapter/spark/SparkRules.java | 7 +--
9 files changed, 117 insertions(+), 26 deletions(-)
There are also --numstat
还有 --numstat
$ git diff --numstat HEAD~5 HEAD
40 10 core/src/main/java/org/apache/calcite/rex/RexSimplify.java
1 1 core/src/main/java/org/apache/calcite/sql/fun/SqlTrimFunction.java
16 0 core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
8 11 core/src/main/java/org/apache/calcite/util/SaffronProperties.java
24 0 core/src/test/java/org/apache/calcite/test/RexProgramTest.java
8 0 core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
15 0 core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
1 1 pom.xml
4 3 spark/src/main/java/org/apache/calcite/adapter/spark/SparkRules.java
and --shortstat
和 --shortstat
$ git diff --shortstat HEAD~5 HEAD
9 files changed, 117 insertions(+), 26 deletions(-)
回答by Tim James
But for seeing the files changed between your branch and its common ancestor with another branch (say origin/master):
但是为了查看您的分支及其与另一个分支的共同祖先之间的文件更改(例如 origin/master):
git diff --name-only `git merge-base origin/master HEAD`
回答by Max MacLeod
To supplement @artfulrobot's answer, if you want to show changed files between two branches:
为了补充@artfulrobot 的回答,如果您想在两个分支之间显示更改的文件:
git diff --name-status mybranch..myotherbranch
Be careful on precedence. If you place the newer branch first then it would show files as deleted rather than added.
小心优先。如果您首先放置较新的分支,那么它会将文件显示为已删除而不是已添加。
Adding a grep
can refine things further:
添加一个grep
可以进一步完善:
git diff --name-status mybranch..myotherbranch | grep "A\t"
That will then show only files added in myotherbranch
.
然后将仅显示添加到myotherbranch
.
回答by Zorayr
Add below alias to your ~/.bash_profile
, then run, source ~/.bash_profile
; now anytime you need to see the updated files in the last commit, run, showfiles
from your git repository.
将以下别名添加到您的~/.bash_profile
, 然后运行, source ~/.bash_profile
; 现在,您可以随时showfiles
从 git 存储库中查看上次提交、运行中更新的文件。
alias showfiles='git show --pretty="format:" --name-only'
回答by Julio Marins
This will show the changes in files:
这将显示文件中的更改:
git diff --word-diff SHA1 SHA2
回答by Parris
Also note, if you just want to see the changed files between the last commit and the one before it. This works fine: git show --name-only
另请注意,如果您只想查看上次提交与其之前的提交之间更改的文件。这工作正常:git show --name-only
回答by Agni
Use git log --pretty=oneline >C:\filename.log
使用 git log --pretty=oneline >C:\filename.log
which will log only a oneline (--pretty=oneline) thats the name of the changed file. Also will log all the details to your output file.
这将仅记录一行(--pretty=oneline),即更改后的文件的名称。还将所有详细信息记录到您的输出文件中。
回答by Jaime Montoya
As artfulrobot said in his answer:
正如 artfulrobot 在他的回答中所说:
git diff --name-status [SHA1 [SHA2]]
My example:
我的例子:
git diff --name-status 78a09k12067c24d8f117886c4723ccf111af4997
4b95d595812211553070046bf2ebd807c0862cca
M views/layouts/default.ctp
M webroot/css/theme.css
A webroot/img/theme/logo.png