I have a huge git repo that eventually want to clean up with bfg.
But first, I want to track down and remove files in the HEAD
which git treats as binary...
So, what i'm looking for is a command to find all files in the HEAD that git treats as binary.
These didn't help:
Thank you in advance for your help.
Use the terminal to display the . git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files.
Git cannot diff binary files. It will upload entire file into repository and will store it pretty much forever. It will also store every single version of every single binary file within the repository.
While browsing your Git repository, start typing in the path control box to search for the file or folder you are looking for.
git ls-files --unmerged and git ls-files --stage can be used to examine detailed information on unmerged paths. For an unmerged path, instead of recording a single mode/SHA-1 pair, the index records up to three such pairs; one from tree O in stage 1, A in stage 2, and B in stage 3.
diff <(git grep -Ic '') <(git grep -c '') | grep '^>' | cut -d : -f 1 | cut -d ' ' -f 2-
Breaking it down:
git grep -c ''
prints the names and line counts of each file in the repository. Adding the -I
option makes the command ignore binary files.diff <(cmd1) <(cmd2)
uses process substitution to provide diff
with named pipes through which the output of cmd1
and cmd2
are sent.grep
and cut
commands are used to extract the filenames from the output of diff
.A simplified solution based on the answer of @jangler (https://stackoverflow.com/a/30690662/808101)
comm -13 <(git grep -Il '' | sort -u) <(git grep -al '' | sort -u)
Explanation:
git grep
-l
Ask to only print the filename of file matching the pattern ''
(which should match with every line of every file)-I
This option makes the command ignore binary files-a
This option force to process binary files as if they were textsort -u
Sort the result of the grep, since comm
only process sorted files
comm -13
List the files that are unique to the 2nd list (the git grep
list with all files including the binary ones)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With