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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:30:55  来源:igfitidea点击:

Git: 1.List all files in a branch, 2.compare files from different branch

git

提问by Scud

  1. Looking for a command like ls -Ror dir/sthat can list all files in a commit/branch.
  2. Is there any command that can compare two files from different branches?
  1. 寻找像ls -Rdir/s这样的命令可以列出提交/分支中的所有文件。
  2. 是否有任何命令可以比较来自不同分支的两个文件?

回答by Jakub Nar?bski

  1. git ls-tree -r --name-only <commit>(where instead of <commit>there can be <branch>).
    You might want to use also -toption which lists subdirectories before descending into them
  2. git diff <branchA>:<fileA> <branchB>:<fileB>,
    or if you want to compare the same file git diff <branchA> <branchB> -- <file>
  1. git ls-tree -r --name-only <commit>(而不是<commit>那里可以<branch>)。
    您可能还想使用-t在下降到子目录之前列出子目录的选项
  2. 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-filesto list all files recursively in the current index/working directory. You may refer to Git-SCM Docs / git-ls-filesor type man git-ls-filesif 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, ignoredor othersfor the untracked. It also supports matching patterns. Having also a --debugarg, you can easily list creation time, modification time, inode id, owner & group id, sizeand flagsfor files.

它有很好的选项就像不同的方式来显示文件cachedstageddeletedmodifiedignoredothers为未跟踪。它还支持匹配模式。也有--debug阿根廷,你可以很容易地列出creation timemodification timeinode idowner & group idsizeflags的文件。



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

  1. Try git ls-filesdescribed in the git-scm docu:
  1. 尝试git ls-filesgit-scm 文档中描述:
# Switch to <branch> of interest
$ git checkout <branch>
# List all files in <branch>
$ git ls-files

For further options check the documentation.

有关更多选项,请查看文档