I am new by Git and trying to know how git merge command works. So I tried a simple git project for example:
I have two branches: master and b. You can see git log for both here (1,2,4 are sample files that are created in branches):
* cf3456b (HEAD, b) add and modify 4 in b
* 68b9086 edit 1 in branch b
| * 81e6490 (master) remove 1 from branch b1
| * e0a6844 modify 2 in branch b1
| * 06bad1d add2 in branch b1
|/
* c667d3b add 1 in branch master
So
master only has one file: 2
b only has two files: 1,4
Now when I try to do:
git merge master
I saw this message:
CONFLICT (modify/delete): 1 deleted in master and modified in HEAD. Version HEAD of 1 left in tree. Automatic merge failed; fix conflicts and then commit the result.
That is strange for me, I thought before that:
mergelike acheckouttries to copy content from latest commit ofmerge inbranch to latest commit ofmerge intobranch but opposite ofcheckout,mergetries to do not change any file inmerge into.And finally if bothmerge inandmerge intobranches have same file with different status, conflict occurs.- I know that
gitonly savessnapshotof files instead ofdifferences. So how git know about changes in latest commits of branches? (In message you can see1 deleted in master and modified in HEADwhich are differences)
Now if my thought was true, no conflict should occur for file 1. So my thought is not true, but how merge works really?