Question

There are two branches in my project: R1 and OPE

Original folder structure of both the branches was:

dev-core/projectX/java-files

Now we started working on OPE branch and meanwhile root folder in R1 branch was renamed from dev-core to core. Now folder structure of R1 branch is:

core/projectX/java-files

and folder structure of OPE branch is:

dev-core/projectX/java-files

I have to merge changes of R1 branch in my OPE branch. Now if I do a simple git merge R1, git is creating a dev-core folder in R1 branch and duplicating all the files in it.

I tried to rename folders in OPE by using git mv and then tried doing git merge R1, it is giving me following message for almost all files:

CONFLICT (rename/delete): core/projectX/path/to/java/file deleted in R1
  and renamed in HEAD. Version HEAD of core/projectX/path/to/java/file
  left in tree.

Now when I am checking the file and looking for conflicts (by searching for symbol <<<) I am not able find any conflicts. Can anyone please explain me what is happening here and how can I fix this?

Note: I used --no-commit option while merging.

More Info

This is how I did the merge:

git checkout -b OPE origin/OPE
git checkout -b R1 origin/R1
git checkout OPE
git mv dev-core core
git merge R1

Here is my understanding of whats happening: Lets say if there is a file dev-core/projectX/file1. I made some changes to this file in my OPE branch and committed it. Now somebody else made some change in core/projectX/file1 in R1 branch. Now when I'll merge there are two possibilities:

  1. Either git will merge both versions of file1 and will show me the conflict using <<<<<

  2. OR git will sense that file1 is renamed from dev-core/projectX/file1 to core/projectX/file1 and will let me keep my file and will discard the changes from R1 branch file If I am correct then 2nd scenarios is my case and this might cause me loss of imp code Plz correct me if I'm wrong.

I tested renaming folders in git and my understanding was wrong. :( git detects folder renaming and will merge smartly. Now I have to figure out problem in my case.

Ahaaa I found my mistake, git is smart and I tried to be oversmart ;) All I had to do was git merge me doing git mv dev-core core added hell lot of complexity and caused lot of trouble :P

Was it helpful?

Solution 2

The solution to my problem is don't rename folder using git mv dev-core core just merge. Git will take care of everything.

In case you see two folder dev-core and core in your workspace that means git was not able to merge some files and they are kept at old location only. Just compare both files dev-core/projectX/file1 & core/projectX/file1 using some comparing tool and fix the problem. Delete old file and you are done :)

OTHER TIPS

You're not going to see files with conflict markers, the conflict says

CONFLICT (rename/delete): core/projectX/path/to/java/file deleted in R1
    and renamed in HEAD.

which means there's a conflict because the file was renamed in your current branch, while it was deleted altogether in R1.

You have to tell git how to resolve that conflict (i.e. do you want to rename the file, or delete it?). Git left behind the renamed version of the file in your working copy:

Version HEAD of core/projectX/path/to/java/file left in tree.

If you do git status, you'll see something like this:

$ git status
On branch test
Your branch and 'origin/test' have diverged,
and have 1 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)

You have unmerged paths.
  (fix conflicts and run "git commit")

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        added by them:      core/projectX/path/to/java/file

You can either choose to keep the renamed version of the file by doing git add <file>, or you can remove it by using git rm <file>. Then commit the changes. That's how you resolve the merge conflict in this case.

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