由于移动的文件导致git合并冲突

时间:2014-07-23 07:48:02

标签: git git-merge merge-conflict-resolution

到目前为止,我还没有用git做过这么多。现在,我有以下问题。 当我做了一些本地修改和提交时,我的同事在一个新分支内重组了文件和文件夹。然后,我添加了一个远程跟踪分支(反映他的更改),并尝试将我的修改合并到其中。当然,当文件移动到另一个位置时它会失败。我怎么能继续前进? A' git status'告诉我这个:

# On branch develop
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Unmerged paths:
#   (use "git add/rm <file>..." 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 <file>..." 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")

我现在不知道该怎么做......

1 个答案:

答案 0 :(得分:3)

因此,如果您希望保留更改,但是在新文件位置,使用mergetool(因此必须在删除文件之间进行选择,以及更改或保留文件,但他们赢了&# 39;在好的目录中)在任何情况下都不会令人满意。

在这种情况下,在冲突状态下,我会将冲突的文件(在旧目录中)移动到新目录,git添加新文件,git rm旧文件(冲突)和提交。

下面和程序的跟踪(3个文件&#34; file1&#34;,&#34; file2&#34;&#34; file3&#34;已被移动到&#34;文件&#34 ;文件夹并在另一个分支中并行更新,执行移动的分支首先合并,然后更新文件内容的分支在合并之后并发生冲突):

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)
>