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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
m0ngr31
  • 791
  • 13
  • 29
  • Possible duplicate of [How can I list all the deleted files in a git repository?](https://stackoverflow.com/questions/6017987/how-can-i-list-all-the-deleted-files-in-a-git-repository) – Artem Barger Jun 26 '17 at 20:21
  • Possible duplicate of [Find and restore a deleted file in a Git repository](https://stackoverflow.com/questions/953481/find-and-restore-a-deleted-file-in-a-git-repository) – Solomon Slow Jun 26 '17 at 20:36

1 Answers1

3

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.

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • If I run with the 'm' flag, it shows when the file was modified, but doesn't show it being re-named or anything. – m0ngr31 Jun 26 '17 at 21:08
  • If it showed when the file was modified, then you must've used `M`. What you want is `m` – Mark Adelsberger Jun 26 '17 at 21:15
  • That shows it being created: `create mode 100644 filename.js`, but not anything else. – m0ngr31 Jun 26 '17 at 21:23
  • In that case, removal of the file from that path has not been committed in a way that's reachable from any ref. – Mark Adelsberger Jun 27 '17 at 12:19
  • Do you know what would cause that? – m0ngr31 Jun 27 '17 at 17:11
  • It's not exactly the right question. If it hasn't been deleted in the commits, then the question is, why are you thinking it has? New version of the answer might shed some light on it. – Mark Adelsberger Jun 27 '17 at 17:51
  • I see what you are saying now. `git log --full-history --diff-filter=A --summary | grep filename` doesn't return anything, but `git log --all --full-history --diff-filter=A --summary | grep filename` does show it being created. So I guess I need to figure out what branch it's hiding on. – m0ngr31 Jun 27 '17 at 19:38