Question

I try to merge two branches, say br2 into br1 (on br1 git merge br2). 1.txt is a file which is present on both branches. In br2 this file is moved into another directory 1.txt is now in sub/1.txt. After merge is done I have two files 1.txt in br1: 1.txt and sub/1.txt, that is strange.

If I apply commit which moved 1.txt file with cherry-pick file is correctly moved to subdirectory.

Why is not it moved (but copied) into subdirectory during merge?

$ git --version
git version 1.8.1.1
Was it helpful?

Solution

I found answer. There was a problem with merge base. Basically diff from head to merge-base did not contain file deletion, so that is why git removed files with cherry pick and did not with merge.

OTHER TIPS

Maybe you didn't removed explicitly the file on br2?

The usual way to move a file is using git mv. That would be:

git checkout br2
git mv 1.txt sub # Moving 1.txt to sub/ using git mv command
git commit

git checkout br1 
git merge br2    # You should see now the file 1.txt only on sub/

If you made something like that, one possibility is that for some reason 1.txt was "introduced" on the top folder by some commit that is on br1 and not on br2, therefore doing the merge between those branches will keep them both.

Maybe I can understand better if if you post git log <hash-of-commit-where-you-moved-the-file> --stat --pretty=oneline --abbrev-commit and/or git log 1.txt on the branch where is not supposed to be.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top