到目前为止,我还没有对 git 做过太多。现在,我有以下问题。 当我进行一些本地修改和提交时,我的同事在一个新分支中重组了文件和文件夹。然后,我添加了一个远程跟踪分支(反射(reflect)他的更改)并尝试将我的修改 merge 到其中。当然,当文件移动到另一个位置时它会失败。我怎样才能继续前进? “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")
我现在不知道该怎么办......
最佳答案
如果因此,您想要保留您的更改,但在新文件位置,使用 mergetool(因此必须在删除文件和您的更改之间做出选择,或保留文件,但它们不会' t 在好的目录中)在任何情况下都不会令人满意。
在这种情况下,当处于冲突状态时,我会将冲突文件(位于旧目录中)移动到新目录,git add 新文件,git rm 旧文件(冲突)并提交。
下面是过程的跟踪(3 个文件“file1”、“file2”和“file3”已被移动到“files”文件夹中并在另一个分支中并行更新,执行移动的分支首先被 merge 并且然后更新文件内容的分支在冲突之后 merge ):
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 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24904653/