Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.
You can use git diff --name-status, that will show you files that where added, modified and deleted.
Git keeps a log of all the changes made to files within a repository. You can restore a file that you have deleted since a previous commit by using the git checkout command. This command lets you navigate to a previous point in your repository's history.
To do what you used to do with git reset -- file , you just run git restore --staged -- file . That is, you tell git restore to copy from HEAD to staging area / index, which is how git reset operates.
git show HEAD^:path/to/file
You can use an explicit commit identifier or HEAD~n to see older versions or if there has been more than one commit since you deleted it.
If this is a file you've deleted a while back and don't want to hunt for a revision, you can use (the file is named foo in this example; you can use a full path):
git show $(git rev-list --max-count=1 --all -- foo)^:foo
The rev-list invocation looks for all the revisions of foo but only lists one. Since rev-list lists in reverse chronological order, then what it lists is the last revision that changed foo, which would be the commit that deleted foo. (This is based on the assumption that git does not allow a deleted file to be changed and yet remain deleted.) You cannot just use the revision that rev-list returns as-is because foo no longer exists there. You have to ask for the one just before it which contains the last revision of the file, hence the ^ in git show.
Since you might not recall the exact path, you can instead get the sha1 from git log then you can simply issue
git cat-file -p <sha1>
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