git 如何列出提交中的所有文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/424071/
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 all the files in a commit?
提问by Philip Fourie
I am looking for a simple git
command that provides a nicely formatted list of all files that were part of the commit given by a hash (SHA1), with no extraneous information.
我正在寻找一个简单的git
命令,它提供一个格式良好的所有文件列表,这些文件是由散列 (SHA1) 给出的提交的一部分,没有无关的信息。
I have tried:
我试过了:
git show a303aa90779efdd2f6b9d90693e2cbbbe4613c1d
Although it lists the files, it also includes unwanted diff information for each.
虽然它列出了文件,但它也包括每个文件不需要的差异信息。
Is there another git
command that will provide just the list I want, so that I can avoid parsing it from the git show
output?
是否有另一个git
命令只提供我想要的列表,这样我就可以避免从git show
输出中解析它?
回答by Ryan McGeary
Preferred Way(because it's a plumbingcommand; meant to be programmatic):
首选方式(因为它是一个管道命令;意味着是程序化的):
$ git diff-tree --no-commit-id --name-only -r bd61ad98
index.html
javascript/application.js
javascript/ie6.js
Another Way(less preferred for scripts, because it's a porcelaincommand; meant to be user-facing)
另一种方式(脚本不太喜欢,因为它是一个瓷器命令;意味着面向用户)
$ git show --pretty="" --name-only bd61ad98
index.html
javascript/application.js
javascript/ie6.js
- The
--no-commit-id
suppresses the commit ID output. - The
--pretty
argument specifies an empty format string to avoid the cruft at the beginning. - The
--name-only
argument shows only the file names that were affected (Thanks Hank). Use--name-status
instead, if you want to see what happened to each file (Deleted, Modified, Added) - The
-r
argument is to recurse into sub-trees
- 的
--no-commit-id
抑制提交ID输出。 - 该
--pretty
参数指定了一个空的格式字符串,以避免在一开始的残余。 - 该
--name-only
参数仅显示受影响的文件名(感谢 Hank)。使用--name-status
相反,如果你想看看发生了什么,以每个文件(deleted,中号odified,一个dded) - 该
-r
参数是递归到子树
回答by Jakub Nar?bski
If you want to get list of changed files:
如果要获取已更改文件的列表:
git diff-tree --no-commit-id --name-only -r <commit-ish>
If you want to get list of all files in a commit, you can use
如果要获取提交中所有文件的列表,可以使用
git ls-tree --name-only -r <commit-ish>
回答by Hank Gay
I'll just assume that gitk
is not desired for this. In that case, try git show --name-only <sha>
.
我只是假设这gitk
是不想要的。在这种情况下,请尝试git show --name-only <sha>
.
回答by Tuxdude
I personally use the combination of --statand --onelinewith the showcommand:
我个人将--stat和--oneline与show命令结合使用:
git show --stat --oneline HEAD
git show --stat --oneline b24f5fb
git show --stat --oneline HEAD^^..HEAD
If you do not like/want the addition/removal stats, you can replace --statwith --name-only
如果您不喜欢/想要添加/删除统计信息,您可以将--stat替换为--name-only
git show --name-only --oneline HEAD
git show --name-only --oneline b24f5fb
git show --name-only --oneline HEAD^^..HEAD
回答by Indu Devanath
You can also do
你也可以这样做
git log --name-only
and you can browse through various commits, commit messages and the changed files.
您可以浏览各种提交、提交消息和更改的文件。
Type q to get your prompt back.
键入 q 以恢复提示。
回答by lunohodov
Recently I needed to list all changed files between two commits. So I used this (also *nix specific) command
最近我需要列出两次提交之间所有更改的文件。所以我使用了这个(也是 *nix 特定的)命令
git show --pretty="format:" --name-only START_COMMIT..END_COMMIT | sort | uniq
Update: Or as Ethan points out below
更新:或者正如 Ethan 在下面指出的那样
git diff --name-only START_COMMIT..END_COMMIT
Using --name-status
will also include the change (added, modified, deleted etc) next to each file
使用--name-status
还将包括每个文件旁边的更改(添加、修改、删除等)
git diff --name-status START_COMMIT..END_COMMIT
回答by VaTo
Simplest form:
最简单的形式:
git show --stat (hash)
git show --stat (hash)
That's easier to remember and it will give you all the information you need.
这更容易记住,它会给你你需要的所有信息。
If you really want only the names of the files you could add the --name-only
option.
如果您真的只想要文件的名称,则可以添加该--name-only
选项。
git show --stat --name-only (hash)
git show --stat --name-only (hash)
回答by takeshin
I use changedalias a quite often. To set it up:
我经常使用更改的别名 a。要设置它:
git config --global alias.changed 'show --pretty="format:" --name-only'
then:
然后:
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)
Similar commands that may be useful:
可能有用的类似命令:
git log --name-status --oneline (very similar, but shows what actually happened M/C/D)
git show --name-only
回答by alpha_989
Use
用
git log --name-status
This will show you the commit id, message, the files changed and whether it was modified, created, added or deleted. Somewhat of a all-in-one command.
这将显示提交 ID、消息、更改的文件以及它是否被修改、创建、添加或删除。有点多合一的命令。
回答by vquintans
Using standard git diff command(also good for scripting):
使用标准的 git diff 命令(也适用于脚本):
git diff --name-only <sha>^ <sha>
If you want also the status of the changed files:
如果您还想要更改文件的状态:
git diff --name-status <sha>^ <sha>
This works well with merge commits.
这适用于合并提交。