如何仅列出两次提交之间更改的文件名
我在存储库中有一堆提交。我想查看两次提交之间更改的文件列表 - 从 SHA1 到 SHA2。
我应该使用什么命令?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
您只需要包含足够的 SHA 哈希来识别提交。 SHA 的顺序并不重要。输出(包括相对路径,而不仅仅是文件名)遵循以下格式:
例如,您还可以
查看第十个最新提交和第五个最新提交(左右)之间的差异。
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:
You can also do, for example
to see the differences between the tenth latest commit and the fifth latest (or so).
就像 --name-only 一样,只不过你会得到一个简单的前缀,告诉你文件发生了什么(修改、删除、添加...),
类似,但提交会在提交消息之后列出,因此你可以看到文件何时发生被改变了。
如果您对某些文件/文件夹发生的情况感兴趣,您可以附加
--; [...]
到git log
版本。如果您想查看单个提交发生的情况,请将其称为 SHA1,然后执行
git log --name-status --oneline [SHA1^..SHA1]
文件状态标志:
M
C
R
A
D
U
is like --name-only, except you get a simple prefix telling you what happened to the file (modified, deleted, added...)
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]
File status flags:
M
C
R
A
D
U
好像没有人提到开关
--stat
:还有
--numstat
和
--shortstat
It seems that no one has mentioned the switch
--stat
:There are also
--numstat
and
--shortstat
但是要查看您的分支及其与另一个分支(例如 origin/master)的共同祖先之间的文件更改:
But for seeing the files changed between your branch and its common ancestor with another branch (say origin/master):
之前每个答案的最大问题是,如果您想使用试图从存储库中获取的信息,您会被输入寻呼机,这是非常烦人的。
特别是如果您是一名开发人员,宁愿学习您要开发的应用程序的业务逻辑,而不是学习 vim 命令。
使用 --no-pager 可以解决这个问题。
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.
为了补充@artfulrobot的答案,如果你想显示两个分支之间更改的文件:
请注意优先级。如果您首先放置较新的分支,那么它会将文件显示为已删除而不是已添加。
添加
grep
可以进一步优化:这样将仅显示
myotherbranch
中添加的文件。To supplement @artfulrobot's answer, if you want to show changed files between two branches:
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:That will then show only files added in
myotherbranch
.另请注意,如果您只想查看最后一次提交和之前的提交之间更改的文件,这可以正常工作:
Also note, if you just want to see the changed files between the last commit and the one before it, this works fine:
将以下别名添加到您的
~/.bash_profile
文件中,然后运行 source ~/.bash_profile
;现在,只要您需要查看上次提交中更新的文件,请从 git 存储库运行showfiles
。Add the below alias to your
~/.bash_profile
file, and then runsource ~/.bash_profile
; now anytime you need to see the updated files in the last commit, run,showfiles
from your git repository.以下对我来说效果很好:
它也可以与单个提交一起使用:
这对于在 Jenkins,其中为您提供了变更集 SHA 哈希值的列表,并且想要迭代它们以查看哪些文件已更改。
这与之前的几个答案类似,但使用
tformat:
而不是format:
会删除提交之间的分隔符空间。The following works well for me:
It can also be used with a single commit:
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 thanformat:
removes the separator space between commits.这将显示文件中的更改:
This will show the changes in files:
对于只需要关注 Java 文件的人来说,这是我的解决方案:
Just for someone who needs to focus only on Java files, this is my solution:
如果有人正在查找已更改文件的列表,包括暂存文件,
如果您需要绝对路径,请删除
--relative
。In case someone is looking for the list of changed files, including staged files
Remove
--relative
if you want absolute paths.使用
它只会记录一行 (
--pretty=oneline
),它是已更改文件的名称。它还会将所有详细信息记录到您的输出文件中。Use
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.基于 git diff --name-status 我写了 git-diffview Git 扩展,它呈现两个路径之间发生的更改的分层树视图。
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.正如 artfulrobot 在他的回答中所说:
我的例子:
As artfulrobot said in his answer:
My example: