[英]How to resolve merge conflict when one branch has modified a file and the other has moved it (but git thinks it has been deleted and a new file made)
I am trying to pull master-dev into my branch.我正在尝试将 master-dev 拉入我的分支。 My branch has moved a file (git sees this as the file being deleted and a new file made), but the same file has been modified in master-dev.
我的分支移动了一个文件(git 将其视为正在删除的文件并创建了一个新文件),但同一文件已在 master-dev 中进行了修改。
I have moved it from 'a/myfile.py' to 'b/myfile.py'.我已将其从“a/myfile.py”移至“b/myfile.py”。
I want to get the changes from master-dev, but have the file in the new location.我想从 master-dev 获取更改,但将文件放在新位置。
There may have also been changes made after moving the file in my branch, if this is the case, I would like to see both sets of changes and then pick the best change.在我的分支中移动文件后也可能进行了更改,如果是这种情况,我希望看到两组更改,然后选择最佳更改。
I have checked out my branch, and then run git pull origin master-dev
.我检查了我的分支,然后运行
git pull origin master-dev
。 It reported merge conflicts, so I ran git mergetool
, which I have configured to use MELD.它报告了合并冲突,所以我运行了
git mergetool
,我已将其配置为使用 MELD。
I have resolved a few other conflicts, but it has now reached the file in question, and git mergetool
has prompted:我已经解决了其他几个冲突,但是现在已经到了有问题的文件,
git mergetool
提示:
Deleted merge conflict for 'a/myfile.py':
{local}: deleted
{remote}: modified file
Use (m)odified or (d)eleted file, or (a)bort?
But unlike the other conflicts it has not opened meld, so I cannot see what the changes are in {remote}
ie master-dev
.但与其他冲突不同,它没有打开 meld,所以我看不到
{remote}
即master-dev
有什么变化。 I also do not know if the file was changes as well as moved.我也不知道文件是否被更改和移动过。
Can I tell git to delete this file, but then compare the changes between the {remote}
and the new file?我可以告诉 git 删除这个文件,然后比较
{remote}
和新文件之间的变化吗? Or is there another solution to this problem?或者这个问题有另一种解决方案吗?
Is there a manual solution to this?是否有手动解决方案? What steps should I take to ensure that I do this cleanly without loosing any potential good changes from either branch?
我应该采取什么步骤来确保在不丢失任何一个分支的任何潜在良好更改的情况下干净地执行此操作?
Thanks.谢谢。
You can use the standard patch
utility to directly apply the diff to the renamed file:您可以使用标准
patch
实用程序直接将差异应用到重命名的文件:
# 3 dots :
git diff my_branch...master-dev -- a/myfile.py |\
patch b/myfile.py
If that works, "solving" the conflict consists in deleting the old file ( (d)
option)如果可行,“解决”冲突包括删除旧文件(
(d)
选项)
About the 3 dots notation in git diff
, quoting git help diff
:关于
git diff
中的 3 点符号,引用git help diff
:
git diff [<options>] <commit>...<commit> [--] [<path>…]
This form is to view the changes on the branch containing and up to the second
<commit>
, starting at a common ancestor of both<commit>
.此表单用于查看包含和直到第二个
<commit>
的分支上的更改,从两个<commit>
的共同祖先开始。git diff A...B
is equivalent togit diff $(git merge-base AB) B
.git diff A...B
相当于git diff $(git merge-base AB) B
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.