Git: List all files in a directory by all branches?

I have the files I'm looking for, but I'm not sure which branch they got into. I would like to list all the files for this directory in all branches.

My question is: in git, is there a way to list all the files in a directory by all branches?

+6
source share
2 answers

You can get files in a directory using git ls-tree .

Here I write the output of git ls-tree to a file.

 $ for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do git ls-tree -r --name-only $branch <directory> >> file-list ; done 

You can get unique files:

 sort -u file-list 
+3
source

Use git ls-tree -r to recursively list all files for a specific tree. Combine with git for-each-ref to list branches and some shell filtering.

 for i in $(git for-each-ref '--format=%(refname)' 'refs/heads/*') ; do echo $i git ls-tree -r $i | awk '$4 ~ /filename-pattern/ {print $4}' echo done 

Replace filename-pattern correct regular expression that matches the files you are interested in. Remember to hide any slashes along the way.

+1
source

Source: https://habr.com/ru/post/979392/


All Articles