Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of files in another branch without checkout

Tags:

git

git-show

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)?

like image 856
Flux Avatar asked Oct 25 '25 03:10

Flux


1 Answers

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.

like image 162
j6t Avatar answered Oct 26 '25 18:10

j6t