如何仅列出两次提交之间更改的文件名

发布于 2024-08-07 04:57:30 字数 89 浏览 4 评论 0原文

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

我应该使用什么命令?

I have a bunch of commits in the repository. I want to see a list of files changed between two commits - from SHA1 to SHA2.

What command should I use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

清风疏影 2024-08-14 04:57:30
git diff --name-only SHA1 SHA2

您只需要包含足够的 SHA 哈希来识别提交。 SHA 的顺序并不重要。输出(包括相对路径,而不仅仅是文件名)遵循以下格式:

 dir 1/dir 2/filename.ext
 dir 3/dir 4/other filename.ext

例如,您还可以

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

查看第十个最新提交和第五个最新提交(左右)之间的差异。

git diff --name-only SHA1 SHA2

where you only need to include enough of the SHA hash to identify the commits. The order of the SHAs does not matter. The output (which includes the relative path, not just the file name) follows this format:

 dir 1/dir 2/filename.ext
 dir 3/dir 4/other filename.ext

You can also do, for example

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

to see the differences between the tenth latest commit and the fifth latest (or so).

も星光 2024-08-14 04:57:30
git diff --name-status [SHA1 [SHA2]]

就像 --name-only 一样,只不过你会得到一个简单的前缀,告诉你文件发生了什么(修改、删除、添加...),

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

类似,但提交会在提交消息之后列出,因此你可以看到文件何时发生被改变了。

  • 如果您对某些文件/文件夹发生的情况感兴趣,您可以附加 --; [...]git log 版本。

  • 如果您想查看单个提交发生的情况,请将其称为 SHA1,然后执行
    git log --name-status --oneline [SHA1^..SHA1]

文件状态标志:

标志名称含义
M已修改文件已被修改
Ccopy-edit文件已被复制和修改
Rrename-edit文件已被重命名和修改
A添加文件已添加
D已删除文件已被删除
U未合并文件在合并后存在冲突
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...)

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 the git 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]

File status flags:

FlagNameMeaning
MmodifiedFile has been modified
Ccopy-editFile has been copied and modified
Rrename-editFile has been renamed and modified
AaddedFile has been added
DdeletedFile has been deleted
UunmergedFile has conflicts after a merge
一页 2024-08-14 04:57:30

好像没有人提到开关--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(-)

还有--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

--shortstat

$ git diff --shortstat HEAD~5 HEAD
9 files changed, 117 insertions(+), 26 deletions(-)

It seems that no one has mentioned the switch --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

$ 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

$ git diff --shortstat HEAD~5 HEAD
9 files changed, 117 insertions(+), 26 deletions(-)
羁客 2024-08-14 04:57:30

但是要查看您的分支及其与另一个分支(例如 origin/master)的共同祖先之间的文件更改:

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

But for seeing the files changed between your branch and its common ancestor with another branch (say origin/master):

git diff --name-only `git merge-base origin/master HEAD`
半城柳色半声笛 2024-08-14 04:57:30

之前每个答案的最大问题是,如果您想使用试图从存储库中获取的信息,您会被输入寻呼机,这是非常烦人的。
特别是如果您是一名开发人员,宁愿学习您要开发的应用程序的业务逻辑,而不是学习 vim 命令。

使用 --no-pager 可以解决这个问题。

git --no-pager diff --name-only sha1 sha2

The biggest issue with every previous answer is that you get fed into a pager which is extremely annoying if you want to use the information you're trying to get out of the repository.
Especially if you're a developer that would rather be learning the business logic of the application your supposed to be developing instead of learning vim commands.

Using --no-pager solves that issue.

git --no-pager diff --name-only sha1 sha2
故事未完 2024-08-14 04:57:30

为了补充@artfulrobot的答案,如果你想显示两个分支之间更改的文件:

git diff --name-status mybranch..myotherbranch

请注意优先级。如果您首先放置较新的分支,那么它会将文件显示为已删除而不是已添加。

添加 grep 可以进一步优化:

git diff --name-status mybranch..myotherbranch | grep "A\t"

这样将仅显示 myotherbranch 中添加的文件。

To supplement @artfulrobot's answer, if you want to show changed files between two branches:

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:

git diff --name-status mybranch..myotherbranch | grep "A\t"

That will then show only files added in myotherbranch.

梓梦 2024-08-14 04:57:30

另请注意,如果您只想查看最后一次提交和之前的提交之间更改的文件,这可以正常工作:

git show --name-only

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
深爱不及久伴 2024-08-14 04:57:30

将以下别名添加到您的 ~/.bash_profile 文件中,然后运行 ​​source ~/.bash_profile;现在,只要您需要查看上次提交中更新的文件,请从 git 存储库运行 showfiles

alias showfiles='git show --pretty="format:" --name-only'

Add the below alias to your ~/.bash_profile file, and then run source ~/.bash_profile; now anytime you need to see the updated files in the last commit, run, showfiles from your git repository.

alias showfiles='git show --pretty="format:" --name-only'
情仇皆在手 2024-08-14 04:57:30

以下对我来说效果很好:

git show --name-only --format=tformat: SHA1..SHA2

它也可以与单个提交一起使用:

git show --name-only --format=tformat: SHA1

这对于在 Jenkins,其中为您提供了变更集 SHA 哈希值的列表,并且想要迭代它们以查看哪些文件已更改。

这与之前的几个答案类似,但使用 tformat: 而不是 format: 会删除提交之间的分隔符空间。

The following works well for me:

git show --name-only --format=tformat: SHA1..SHA2

It can also be used with a single commit:

git show --name-only --format=tformat: SHA1

which is handy for use in Jenkins where you are provided with a list of changeset SHA hash values, and want to iterate over them to see which files have been changed.

This is similar to a couple of the previous answers, but using tformat: rather than format: removes the separator space between commits.

绿萝 2024-08-14 04:57:30

这将显示文件中的更改:

git diff --word-diff SHA1 SHA2

This will show the changes in files:

git diff --word-diff SHA1 SHA2
若能看破又如何 2024-08-14 04:57:30

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

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

Just for someone who needs to focus only on Java files, this is my solution:

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

强者自强 2024-08-14 04:57:30

如果有人正在查找已更改文件的列表,包括暂存文件,

git diff HEAD --name-only --relative --diff-filter=AMCR

git diff HEAD --name-only --relative --diff-filter=AMCR sha-1 sha-2

如果您需要绝对路径,请删除 --relative

In case someone is looking for the list of changed files, including staged files

git diff HEAD --name-only --relative --diff-filter=AMCR

git diff HEAD --name-only --relative --diff-filter=AMCR sha-1 sha-2

Remove --relative if you want absolute paths.

献世佛 2024-08-14 04:57:30

使用

git log --pretty=oneline > C:\filename.log

它只会记录一行 (--pretty=oneline),它是已更改文件的名称。它还会将所有详细信息记录到您的输出文件中。

Use

git log --pretty=oneline > C:\filename.log

which will log only a oneline (--pretty=oneline) that's the name of the changed file. It will also log all the details to your output file.

合约呢 2024-08-14 04:57:30

Based on git diff --name-status I wrote the git-diffview Git extension that renders a hierarchical tree view of what changed between two paths.

云裳 2024-08-14 04:57:30

正如 artfulrobot 在他的回答中所说:

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

As artfulrobot said in his answer:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文