1

I'm trying to recover a file that is no longer in a Git repository.

I can see that the file was created for sure when I run this:

git log --all --full-history --diff-filter=A --summary | grep filename 

But I can't find when the file was deleted with this:

git log --all --full-history --diff-filter=D --summary | grep filename 

The file for sure isn't there anymore, so why wouldn't it show up?

2

1 Answer 1

4

UPDATED based on comments.

So the first thing was making sure that the diff-filter wasn't deceiving you, because if git sees the file as "moved" or "renamed" then diff-filter of D won't capture that. But even taking the diff-filter out of the equation doesn't show the file being moved or removed.

That means it has never been moved or removed. If you don't see it in the work tree, then either

(1) Removal of the file is staged but not committed (2) Removal of the file is untracked (3) The file was never on the current branch

I'm betting on (3). The command you used to find the "create" record searches the history of all refs. Take out the --all argument and ask for the history of your current commit

git log --full-history --diff-filter=A --summary | grep filename 

Do you still see the file being created? If not, then it was committed only on a different branch. For example, if you have

x --- x --- H <--(master) \ ^HEAD A --- x <--(develop) 

perhaps the file was added in commit A, which you would see in the history of develop (or when using --all). But of course the file would not be in H (which is what you'd have checked out in this scenario) or its history. So it wasn't deleted.

If the file is created in the current commit's history, but is never removed, then it's in the current commit. The only reason left why you'd not see it is if it's been removed from the work tree, but the delete would be not yet committed and maybe not yet added.

Sign up to request clarification or add additional context in comments.

7 Comments

If I run with the 'm' flag, it shows when the file was modified, but doesn't show it being re-named or anything.
If it showed when the file was modified, then you must've used M. What you want is m
That shows it being created: create mode 100644 filename.js, but not anything else.
In that case, removal of the file from that path has not been committed in a way that's reachable from any ref.
Do you know what would cause that?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.