2

How does git ls-files and git sparse-checkout behave together?

After doing a sparse checkout, I would like to calculate the number of files. If I use git ls-files | wc -l it will give me the same number as if the full repo was checked out. Is this by design? How can I limit the ls-files to only list files that are checked out?

1 Answer 1

3

Try git ls-files -v | grep -e '^H' | wc -l. The checked-out files are marked with a leading H and the hidden ones with S. But make sure the repository is clean. Files of other status have other leading letters.

1
  • Thanks, that works, but feels quite hacky.
    – Moberg
    Commented Mar 31, 2021 at 10:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.