francesco
francesco

Reputation: 7539

list all tracked files in every branch

I know one can use git ls-tree to list all tracked files in a given branch. Is there an efficient way to list all tracked files in all branches?

One can of course write a small script like:

#!/bin/bash
(
  for b in $(git branch --no-color|tr '*' ' '|tr -s " "|cut -d " " -f 2)
  do
     git ls-tree -r "${b}" --name-only
  done
)| sort | uniq

This seems however rather inefficient when there are many branches, and especially if, as usual, most files are tracked in all branches.

Is there a more efficient way to list all tracked files?

Upvotes: 0

Views: 109

Answers (1)

matt
matt

Reputation: 534904

The trouble is that Git has no notion of "all tracked files"; the very idea is meaningless. Git's notion is exactly the notion expressed by ls-tree: for any given commit (or other tree-ish object), what files does it contain?

Well, this is something that Git can do, obviously, for any tree-ish. It happens that you are interested in only those tree-ish object that are commits that have branch names pointing at them. So there is no "royal road" to gather this information; you simply have to specify what commits you are interested in, and look at each of them, one by one.

Upvotes: 1

Related Questions