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

  1. Looking for a command like ls -R or dir/s that can list all files in a commit/branch.
  2. Is there any command that can compare two files from different branches?

  1. 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 them
  2. git diff <branchA>:<fileA> <branchB>:<fileB>,
    or if you want to compare the same file git diff <branchA> <branchB> -- <file>

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

To list all files added in the new branch

git diff --name-only branch1 master

As of 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-files or type man git-ls-files if you have installed Git and have man pages available.

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.


For the diff of two branch, simply use git diff <branch> <other branch> as stated in other answers.


List files in branch with git ls-files

  1. Try git ls-files described in the git-scm docu:
# Switch to <branch> of interest
$ git checkout <branch>
# List all files in <branch>
$ git ls-files

For further options check the documentation.