brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git log --diff-filter=D finds when a file was deleted

Git
~/tips/tip-git-log-diff-filter-deleted

git log --diff-filter=D --summary -- path/to/old-file.php

Lists only the commits that deleted files, so you can find when a file disappeared.

A file is gone and nobody remembers when or why. Plain git log -- path can show it, but it mixes the file’s whole life. A filter on the kind of change gets straight to the deletion.

git log --diff-filter=D --summary -- path/to/old-file.php

--diff-filter keeps only commits that contain the kinds of change you name: A for added, M for modified, R for renamed, D for deleted and a few more. The --summary output lists the file with a line such as delete mode 100644, and the commit message tells you the reason.

To bring the file back, take it from the parent of the deleting commit:

git restore --source=<commit>^ -- path/to/old-file.php

Without a path you get every deletion in the project, which works well to answer “when did we remove that whole folder?”:

git log --diff-filter=D --summary --oneline

Caveats: a file can be deleted and later recreated, so you may see more than one commit. A rename shows up as R and not D when git detects it as a rename, which is why a moved file is not a deletion. Upper-case letters select and lower-case letters exclude, so --diff-filter=d hides deletions.

Further reading: git log, –diff-filter (Git documentation)

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link