I have some files I'm looking for, but that I don't know where they are located in my git repository (both in space and time). I also speculate it is possible that both the files and the branch in which they reside might be deleted.
How could I list every file ever in existence in the whole git repository? I know deleted files / branches could pretty well have already been garbage collected, and well, there's nothing to do about it than to pray it didn't happen already.
Thanks!
This command will list the files that are being tracked currently. If you want a list of files that ever existed use: git log --pretty=format: --name-only --diff-filter=A | sort - | sed '/^$/d'This command will list all the files including deleted files.
The Git Show command allows us to view files as they existed in a previous state. The version can be a commit ID, tag, or even a branch name. The file must be the path to a file. For example, the following would output a contents of a file named internal/example/module.go file from a tagged commit called “release-23”.
Git stores the complete history of your files for a project in a special directory (a.k.a. a folder) called a repository, or repo. This repo is usually in a hidden folder called . git sitting next to your files.
A repository contains all of your project's files and each file's revision history.
This is a bit crazy, but it might do what you want:
#!/bin/sh
content="$@"
for hash in $({
git rev-list --objects --all
git rev-list --objects -g --no-walk --all
git rev-list --objects --no-walk \
$(git fsck --unreachable |
grep '^unreachable commit' |
cut -d' ' -f3)
git fsck --unreachable | grep "^unreachable blob" | cut -d' ' -f3
} 2> /dev/null | cut -d' ' -f1 | sort | uniq); do
if git cat-file blob $hash 2> /dev/null | grep -i $content > /dev/null ; then
echo $hash
fi
done
I tried to get absolutely every blob accessible, and look for a specific content in each of them.
You'll be able to do a git cat-file -p hash
on each of the generated hashes and might find your lost file.
On a side note, I'm surprised to not see any nice way to list absolutely every object available in the repository. I was thinking of unpacking everything and go from there, that could be a better solution too.
Resources:
Related topics:
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