1

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
michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
  • You have msysgit tagged on your question. Is it correct to say that you're using Windows? Have you investigated the possibility that it may be an issue with case-insensitivity for file names on Windows systems? –  Aug 13 '13 at 03:08
  • @Cupcake, file names are in the same case – michael nesterenko Aug 13 '13 at 03:12

2 Answers2

2

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.

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182
1

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.

llekn
  • 3,271
  • 2
  • 18
  • 23
  • `git add .` is [superfluous](http://stackoverflow.com/questions/1094269/whats-the-purpose-of-git-mv). – antak Aug 13 '13 at 03:55
  • You're right @antak, git mv already contains the git add operation. Answer edited! – llekn Aug 13 '13 at 12:52