3

I want to list the files present in another branch without doing a checkout, and according to View a file in a different Git branch without changing branches, this command is sufficient:

git show mybranch:mydir

Unfortunately, the output is not ideal because of the completely unnecessary tree mybranch:mydir:

tree mybranch:mydir

.gitignore
Makefile
README

How can I list the files in another branch without getting any extra information (e.g. tree mybranch:mydir)?

Flux
  • 5,866
  • 4
  • 24
  • 62

1 Answers1

5

That would then be

git -p ls-tree -r --name-only mybranch:mydir

Drop -p if you do not need the pager. Drop -r if you do not want to descend into directories recursively.

j6t
  • 4,718
  • 1
  • 5
  • 18
  • Which Git version is this? I am using Git 2.17.1. I get no output (with exit code 0) when I run this. – Flux Jan 15 '20 at 13:55
  • I have 2.23.0 here. But that should not make a difference; the command hasn't changed since aeons. Show your exact command. – j6t Jan 15 '20 at 13:58
  • Okay, I figured it out. This command must be run from the root of the repository. – Flux Jan 15 '20 at 13:58