git merge由于文件移动而发生冲突 [英] git merge conflict due to moved files

查看:635
本文介绍了git merge由于文件移动而发生冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我对git的工作还不多.现在,我有以下问题. 当我进行一些本地修改和提交时,我的同事在一个新分支中重组了文件和文件夹.然后,我添加了一个远程跟踪分支(反映了他的更改),并尝试将所做的修改合并到其中.当然,由于文件移动到另一个位置而导致失败.我该如何前进? "git status"向我显示了这一点:

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

我不确定现在该怎么办...

I'm not sure what to do now...

推荐答案

因此,如果您要保留更改,但要使用mergetool在新文件位置(因此必须在删除文件之间进行选择,因此无论如何您所做的更改或保留文件,但这些文件都不会放在好目录中).

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.

在这种情况下,当处于冲突状态时,我会将冲突文件(位于旧目录中)移动到新目录中,git添加新文件,git rm旧文件(冲突)并提交.

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.

在该过程的下方和跟踪中(3个文件"file1","file2"和"file3"已移至"files"文件夹中,并在另一个分支中并行更新,执行该分支的分支已首先合并,然后那么更新文件内容的分支将在合并后并发生冲突):

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

这篇关于git merge由于文件移动而发生冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆