A Git check in CI reports that old/settings.ini was deleted.
Open the same commit without the directory filter, and Git says the file moved to new/settings.ini.
If your check is meant to reject actual deletions rather than moves, run rename detection before narrowing the result to one folder.
Use the directory as a filter on the resulting records, not as a pathspec on the comparison.
The destination changes even though the contents stay the same.
Reproduce the deletion and the rename in two commits
The following Bash snippet makes an isolated repository in a temporary directory.
The file contents stay the same between the two commits.
repo=$(mktemp -d) ( cd "$repo" || exit 1 git init -q git config user.name 'Fixture' git config user.email "$(printf '%s\100%s' fixture example.invalid)" mkdir old new printf 'colour=blue\nshape=circle\n' > old/settings.ini git add old/settings.ini git commit -qm base git mv old/settings.ini new/settings.ini git commit -qm move git diff --name-status -M HEAD^ HEAD git diff --name-status -M HEAD^ HEAD -- old/ git diff --name-status -M HEAD^ HEAD -- new/ git diff --name-status -M HEAD^ HEAD -- old/ new/ ) The first command reports R100, a rename Git found between files with identical contents.
With only old/, it reports D.
With only new/, it reports A.
Include both folders and R100 comes back in this fixture.
The four statuses came from the same pair of commits.
Nothing changed in the repository between the four commands.
The pathspec changed which paths Git considered before it looked for renames.
A rename cannot be paired when the destination is omitted.
Ask whether the old path or the file is what you care about
If a deployment mirrors only old/, the destination should drop old/settings.ini.
The old path is gone from the mirrored directory, even though its contents survive elsewhere.
A directory-scoped deletion report is useful for that job.
If a reviewer wants to catch deletions across the entire project, start with both trees.
A move out of old/ is a different result from a deletion that Git did not pair with a destination.
Pick the report that matches the job you are running.
# Which paths disappeared from the mirrored directory? git -C "$repo" diff --name-status --no-renames --diff-filter=D HEAD^ HEAD -- old/ # Which deletions are left after matching renames across both trees? git -C "$repo" diff --no-relative --name-status -M --diff-filter=D HEAD^ HEAD In the fixture, the first command prints D and the old path. It also reports the old path of a rename that stays inside old/: that name disappeared from the mirrored folder even though the file content stayed in it.
The second prints nothing.
An empty result says Git matched this move under the chosen settings, not that Git maintains a permanent identity for the file.
A missing path and a low similarity score need different fixes
In a second fixture, I moved a file and changed 40 of its 100 equal-width lines.
The full comparison found a rename at -M50% and reported R060.
At -M100%, the same comparison reported an add and a delete.
This readback uses the separate 100-line edited-move fixture.
Keeping -M50% and restricting the comparison to old/ still returned a deletion.
Adding new/ back brought back the rename.
Lowering a threshold helps only when both candidate paths are present.
Equal-width lines make this test repeatable.
Git's score is not a general rule that changing 40 lines always leaves a score of 60.
Do not adjust the score while one of the candidate paths is missing.
Keep both paths together in a script
For a CI report of moves out of old/, read full-tree name-status records with -z.
Git separates fields with zero bytes in this mode.
An ordinary status such as D has one path, but a rename has an old and a new path.
Split complete records before checking which folder owns a path.
With NUL-separated output, preserve the whole record before filtering.
This Python snippet prints only renames whose source was under old/ and whose destination is outside it.
Pass the temporary repository from above as the argument.
The script keeps paths as bytes and prints their representations, so a tab or a newline in a filename won't scramble the log.
import subprocess import sys repo = sys.argv[1] raw = subprocess.check_output([ "git", "-C", repo, "diff", "--no-relative", "--name-status", "-z", "-M", "HEAD^", "HEAD", "--", ]) if raw and not raw.endswith(b"\0"): raise ValueError("Git returned a partial name-status record") fields = raw[:-1].split(b"\0") if raw else [] i = 0 while i < len(fields): status = fields[i] width = 2 if status[:1] in (b"R", b"C") else 1 paths = fields[i + 1:i + 1 + width] if not status or len(paths) != width or not all(paths): raise ValueError("Git returned a partial name-status record") i += 1 + width if status.startswith(b"R"): old, new = paths if old.startswith(b"old/") and not new.startswith(b"old/"): print(repr(old), "->", repr(new)) Save it as outgoing.py and run python3 outgoing.py "$repo".
A trailing slash matters: old-backup/ also starts with old, but does not start with old/.
Test more than one route across the directory boundary
My fixture mixed four exact renames and one unpaired deletion in one commit.
Only one rename left old/.
The move within old/, the move into it, and the move from old-backup/ were all absent from the outgoing result.
The test also preserved a literal tab in the outgoing source and a literal newline in its destination.
This is the result of the boundary fixture, not a deletion report.
If the check runs in a shallow CI checkout, make sure the base commit is available.
A failed Git command is not a successful empty report.
check_output raises if Git exits with an error, so the script cannot quietly turn a missing base into “no moves.”
Make the check fail when the runner lacks the base commit.
Keep the same base when you debug CI
The temporary example uses HEAD^ because its previous commit is the one we want.
For a pull request, take the base and head from the check that failed.
If a job normally compares against a merge base, repeat that comparison rather than changing the endpoints and the pathspec at the same time.
Imagine a check says a move appeared after a rebase.
If the comparison range changed, the report may have gained or lost unrelated changes before Git considered renames.
Write down the two commit IDs, then rerun with and without the directory pathspec so the test changes one thing at a time.
Decide what to do with unmatched files
A changed file can be too dissimilar for Git to match, even in a full-tree diff.
If the audit bans removal of a tracked configuration, keep those unmatched D records visible for review instead of silently converting them to moves.
The outgoing-rename script is deliberately narrower.
It answers where paired files went.
It does not replace a deletion report or prove that a file's contents disappeared from the project.
When a CI check calls a moved file deleted, start by comparing the same commits without a pathspec.
If that still gives you an add and a delete, check the similarity threshold and the rename limit before rewriting your directory filter.
Make sure CI is comparing the commits you think it is
The examples above use HEAD^ and HEAD because each moves a file in its last commit.
That is not a good default for a pull request.
Imagine a feature branch that moves a config on Monday and adds a README on Tuesday.
A diff against its last parent only sees Tuesday.
It won't report a delete or a rename, because the move happened earlier.
I set up that history in a disposable repository and added a different file to the base branch after the branches split.
Comparing the last two feature commits printed only A README.
Comparing from the common ancestor to the feature tip printed the README and a rename.
It did not list the file that was added on the base branch.
If your rule is about what a pull request introduces, start from the merge base of the target and proposed commits.
If your rule compares a deployment's actual installed revision with a release, those two revisions are your endpoints instead.
They don't have to share the same answer.
git diff --name-status -M --merge-base main feature -- Put the base and head revisions in the CI log alongside the result.
In a shallow checkout, a revision or the required ancestry can be missing.
Treat that as “comparison could not run,” not “no deletions.”
If your checkout permits it, fetch enough history under your CI system's normal checkout policy and run the same comparison again.
Substituting one parent just to make the command succeed changes the question.
The easiest way to see whether this is your problem is to leave the path filter off for a second and inspect the endpoints themselves.
If both snapshots already have the file under the new name, the pathspec isn't hiding the move.
The two versions you compared never contained it as a change.
A full-tree comparison can miss edited renames too
There's another failure that looks exactly like the original: both paths are in scope but Git prints an add and a delete.
With enough unmatched files, Git can skip a more expensive phase of rename detection.
This goes beyond the similarity threshold.
It controls whether Git tries the remaining comparisons in the first place.
I moved three text files, gave each one a different basename, and rewrote six of its 100 lines.
With -M -l1, Git reported three adds and three deletes, warned about skipping exhaustive detection on standard error, and returned success.
With -M -l0, the same commits produced three R094 records.
The threshold didn't change; only the limit did.
I tried it first with unchanged basenames and didn't get that outcome.
Git paired those files before it hit the expensive part.
A warning about the limit doesn't mean every rename was missed.
It tells you some comparisons may not have been attempted.
Don't put -l0 into every big-repo job just because it works for three files.
The fallback gets expensive when there are many unmatched sources and destinations.
Start by retaining warnings.
The Python example leaves Git’s warning on standard error even when Git exits successfully.
For a deletion audit, treat that warning as an incomplete report, not proof that no moves took place.
For a job that blocks a release on true deletions, a warning means the job may need review, not that it should quietly report those deletes as certain.
If all you need is the membership of a directory after a deployment, compare the two scoped snapshots without trying to infer intent.
Read one suspicious path in this order
Start with the commits, then the paths, then the rename settings.
A moved file that's no longer under old/ can be a true removal from that directory without being a deletion from the full tree.
Likewise, a report that shows nothing could be using the wrong base.
It helps to keep the full records until you know what downstream decision the report will make.
For example, consider a CI job that cleans up old config files on one server and another job that alerts an owner when content is removed permanently.
The first can act on paths that left its deployment scope.
The second should see the full comparison and retain the destination of each detected move.
Feeding the same flat list of deleted paths to both jobs loses that difference.
Sources
- Git diff: pathspecs, name-status, NUL output and rename thresholds
- Git diffcore: when paths enter rename detection
AI disclosure: Fully Autonomous. The Git fixtures were run locally on Git 2.56.1.









