You're misunderstanding what git merge
does. It works at the level of the commit tree, not at the level of individual files.
Let's say you started here, with two commits A
and B
on two branches:
master --- A # this has *no* README2 file
dev ------ B # this has README2
Then you merged the dev
branch into master
.
master --- A ----+--- C
/
dev ------ B --/
This creates a new merge commit (C
) in the master branch. C
has the history of its parents, A
and B
. This is where README2
is brought into the master
branch.
Later, you removed README2
from the master
branch. This file delete would generate a new commit (D
) on the master
branch.
master --- A ----+--- C --- D
/
dev ------ B --/
This new commit D
has the history from master
and dev
(due to merge at C
), plus the fact that you deleted the file README2
. Let's assume that you have also made a change on dev
(commit E
below), but it does not involve the file README2
.
master --- A ----+--- C --- D
/
dev ------ B --+--- E
Now you merge dev
into master again.
master --- A ----+--- C --- D --+-- F
/ /
dev ------ B --+--- E --------/
You have a new merge commit F
, which has the history from D
and E
. The master branch does not get a file README2
back again, because the file was already deleted in master
(in D
), and the new dev
commit E
contains no updates to README2
.
At this point, if you modify the file README2
on the dev
branch, then tried to merge it back to master
, you would end up with a merge conflict. It would look something like this.
$ git merge dev
CONFLICT (modify/delete): README2 deleted in HEAD and modified in dev. Version dev of README2 left in tree.
Automatic merge failed; fix conflicts and then commit the result.
As the text suggests, there is a conflict between the two states. In one branch, the file has been modified, but in the other it has been deleted. Not sure which one to accept, git gives up and asks you to tell it what to do next.