The missing files#
The fixture merges feat, which adds f and g, with a merge commit. Someone reverts that merge with git revert -m 1. The author adds a test file t to feat and merges again. Git reports success:
$ git merge feat
$ ls
a
t
f and g are absent, and there was no conflict. The merge base of main and feat is the commit that added them, so Git sees them as already merged and then deliberately removed. Only t is new. Git's own note on reverting a faulty merge describes this.
When the author edits f on the branch instead of adding a file, the second merge stops with CONFLICT (modify/delete): f deleted in HEAD. That conflict is the luckier case, because somebody looks.
Choose the way back#
| How the change first landed | Reland |
|---|---|
| Merge commit, and the same branch continues | git revert REVERT_SHA, then merge the branch |
| Merge commit, and the author prefers a clean series | git rebase --no-ff BASE on the branch, where BASE is its original branch point, then merge |
| Squash merge | Merge or squash the branch again, then check the result against the branch |
In the fixture, reverting the revert and then merging gave a, f, g and t. So did the rebase onto BASE, which gives every commit of the branch a new ID. Rebasing onto main with the same option replayed only the commit that added t, and f and g stayed missing. After a squash merge and a revert, merging the original branch gave a, f and t: a squash leaves no ancestry between the branch and main, so Git compared the branch with the older base. Run with Git 2.43. Do not generalize the squash result. If main edited the same lines since, you get a conflict instead.
What the person reverting hands over#
- The revert commit and the commit it reverted.
- Whether the original was a merge commit or a squash:
git cat-file -p SHA | grep -c ^parentprints 2 for a merge. - The observation that led to the revert, with time and release.
- What must be true before relanding, as a check someone can run.
- Which row of the table above applies.
Item 4 is the one that goes missing. "Reverted, caused errors" leaves the author to guess whether a new test would satisfy the person who reverted.
Check the relanded tree#
List the paths the feature changed, then compare the two finished trees. Keep the two lists separate so a filename containing spaces stays intact.
git diff --name-status --no-renames BASE feat
git diff --name-status --no-renames feat main
BASE is the commit the branch started from. In the second list, D beside a feature path means the file exists on feat and is missing from main. Explain each difference that affects a path in the first list. If the second list is empty, the two trees match. Run the test that covers the original failure before relanding.
Worked example#
This example is fictional. An on-call engineer reverts an export feature at 02:10 UTC and writes: "Merge commit. Reland by reverting this revert, then merging. Condition: export of an account with no orders returns 200; it returned 500 on release 418." The author adds the test, reverts the revert and merges. Their first attempt had skipped the second step, and the diff above listed two missing files before anyone approved it.
Backports have a related trap. Handing over evidence covers the rest.