false directory/file merge conflict

From: Jeffrey Middleton <hidden>
Date: 2016-06-15 22:47:51

When a directory (with contents) has changed into a file on one
branch, and another branch attempts to merge it, there's a false
conflict - the directory is processed before its contents are removed.
This is particularly nasty, because "resolving" the non-existent
conflict results in no changes, so future merges will fail in exactly
the same way.  Test script and failed merge output below.

Jeffrey

-- 8< --

rm -rf directory-file
mkdir directory-file
cd directory-file
git init

mkdir foo
echo bar > foo/bar
echo bas > foo/baz
git add foo/bar foo/baz
git commit -m "check in files"

git branch foo_unchanged

git rm -r foo
echo foo > foo
git add foo
git commit -m "foo changes from directory to file"

git checkout foo_unchanged
echo foobar > foobar
git add foobar
git commit -m "make a separate change"

git merge master

-- 8< --

CONFLICT (directory/file): There is a directory with name foo in HEAD.
Adding foo as foo~master
Removing foo/bar
Removing foo/baz
Automatic merge failed; fix conflicts and then commit the result.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help