I have not done so much with git so far. Now, I have the following problem.
While I did some local modifications and commits, my colleague restructured files and folders within a new branch. Then, I added a remote tracking branch (reflecting his changes) and tried to merge my modifications into it. Of course it fails as the files moved to another location. How can I go onwards?
A 'git status' shows me this:
# On branch develop
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Unmerged paths:
# (use "git add/rm ..." as appropriate to mark resolution)
#
# deleted by us: src/de/mpicbg/tds/knime/hcstools/prefs/DoubleFieldEditor.java
# deleted by us: src/de/mpicbg/tds/knime/hcstools/prefs/HCSToolsPreferencePage.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/HeatMapModel.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/PlateViewer.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/color/LinearGradientTools.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/dialog/PlateAttributeDialog.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/menu/TrellisMenu.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/menu/ViewMenu.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/menu/WellAttributeComboBox.java
# deleted by us: src/de/mpicbg/tds/knime/heatmap/renderer/HeatTrellis.java
#
# Untracked files:
# (use "git add ..." to include in what will be committed)
#
# bin/
# src/de/mpicbg/tds/knime/heatmap/HeatMapModel.ucls
# src/de/mpicbg/tds/knime/heatmap/diagram.ucls
no changes added to commit (use "git add" and/or "git commit -a")
I'm not sure what to do now...
解决方案
If, as a result, you want to keep your changes, but in the new files location, using mergetool (and thus having to choose between deleting the files, and so your changes, or keeping the files, but they won't be in the good directory) will not be satisfactory in any case.
In this situation, while in conflict state, I would move the conflicting files (which are in the old directory) to the new directory, git add the new files, git rm the old files (conflicting) and commit.
Below and trace of the procedure (3 files "file1", "file2" and "file3" have been moved in a "files" folder and updated in parallel in another branch, the branch doing the move has beed merged first and then the branch updating the files content is merged after and conflicting):
ghislain@debian: /tmp/git-test (master)
> git merge --no-ff add-file-content
CONFLICT (modify/delete): file3 deleted in HEAD and modified in add-file-content. Version add-file-content of file3 left in tree.
CONFLICT (modify/delete): file2 deleted in HEAD and modified in add-file-content. Version add-file-content of file2 left in tree.
CONFLICT (modify/delete): file1 deleted in HEAD and modified in add-file-content. Version add-file-content of file1 left in tree.
Automatic merge failed; fix conflicts and then commit the result.
ghislain@debian: /tmp/git-test (master *+|MERGING)
> git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)
deleted by us: file1
deleted by us: file2
deleted by us: file3
no changes added to commit (use "git add" and/or "git commit -a")
ghislain@debian: /tmp/git-test (master *+|MERGING)
> mv file1 file2 file3 files
ghislain@debian: /tmp/git-test (master *+|MERGING)
> git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)
deleted by us: file1
deleted by us: file2
deleted by us: file3
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: files/file1
modified: files/file2
modified: files/file3
no changes added to commit (use "git add" and/or "git commit -a")
ghislain@debian: /tmp/git-test (master *+|MERGING)
> git add files
ghislain@debian: /tmp/git-test (master *+|MERGING)
> git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
Changes to be committed:
modified: files/file1
modified: files/file2
modified: files/file3
Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)
deleted by us: file1
deleted by us: file2
deleted by us: file3
ghislain@debian: /tmp/git-test (master *+|MERGING)
> git rm file1 file2 file3
file1: needs merge
file2: needs merge
file3: needs merge
rm 'file1'
rm 'file2'
rm 'file3'
ghislain@debian: /tmp/git-test (master +|MERGING)
> git status
On branch master
All conflicts fixed but you are still merging.
(use "git commit" to conclude merge)
Changes to be committed:
modified: files/file1
modified: files/file2
modified: files/file3
ghislain@debian: /tmp/git-test (master +|MERGING)
> git commit
[master 4e478c6] Merge branch 'add-file-content'
ghislain@debian: /tmp/git-test (master)
>