Git:1.列出一个分支中的所有文件,2.比较来自不同分支的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1910783/
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
Git: 1.List all files in a branch, 2.compare files from different branch
提问by Scud
- Looking for a command like
ls -R
ordir/s
that can list all files in a commit/branch. - Is there any command that can compare two files from different branches?
- 寻找像
ls -R
或dir/s
这样的命令可以列出提交/分支中的所有文件。 - 是否有任何命令可以比较来自不同分支的两个文件?
回答by Jakub Nar?bski
git ls-tree -r --name-only <commit>
(where instead of<commit>
there can be<branch>
).
You might want to use also-t
option which lists subdirectories before descending into themgit diff <branchA>:<fileA> <branchB>:<fileB>
,
or if you want to compare the same filegit diff <branchA> <branchB> -- <file>
git ls-tree -r --name-only <commit>
(而不是<commit>
那里可以<branch>
)。
您可能还想使用-t
在下降到子目录之前列出子目录的选项git diff <branchA>:<fileA> <branchB>:<fileB>
,
或者如果你想比较同一个文件git diff <branchA> <branchB> -- <file>
回答by Dan Loewenherz
To compare the same file from different branches:
要比较来自不同分支的相同文件:
git diff branch_1..branch_2 file.txt
To list all files in a tree object:
要列出树对象中的所有文件:
git ls-tree -r branch
回答by Peter Mansell
To list all files added in the new branch
列出新分支中添加的所有文件
git diff --name-only branch1 master
回答by Berkant
As of Git v2.1.0 [08/15/14]
自 Git v2.1.0 [08/15/14]
For listing, you may use git ls-files
to list all files recursively in the current index/working directory. You may refer to Git-SCM Docs / git-ls-filesor type man git-ls-files
if you have installed Git and have man pages available.
对于列表,您可以使用git ls-files
递归列出当前索引/工作目录中的所有文件。如果您已经安装了 Git 并且有可用的手册页,您可以参考Git-SCM Docs / git-ls-files或 type man git-ls-files
。
It has nice options to show files in different ways like cached
, staged
, deleted
, modified
, ignored
or others
for the untracked. It also supports matching patterns. Having also a --debug
arg, you can easily list creation time
, modification time
, inode id
, owner & group id
, size
and flags
for files.
它有很好的选项就像不同的方式来显示文件cached
,staged
,deleted
,modified
,ignored
或others
为未跟踪。它还支持匹配模式。也有--debug
阿根廷,你可以很容易地列出creation time
,modification time
,inode id
,owner & group id
,size
和flags
的文件。
For the diff of two branch, simply use git diff <branch> <other branch>
as stated in other answers.
对于两个分支的差异,只需git diff <branch> <other branch>
按照其他答案中的说明使用即可。
回答by drstoop
List files in branch with git ls-files
列出分支中的文件 git ls-files
- Try
git ls-files
described in the git-scm docu:
- 尝试
git ls-files
在git-scm 文档中描述:
# Switch to <branch> of interest
$ git checkout <branch>
# List all files in <branch>
$ git ls-files
For further options check the documentation.
有关更多选项,请查看文档。