git解决冲突 merge 不提示_git merge由于文件移动而发生冲突

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)

>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值