合并后关于被删除的文件感到困惑的Git rebase [英] Git rebase after merge confused about deleted file
问题描述
我的Git存储库有两个文件,alpha
和beta
,具有相同的内容.
My Git repository has two files, alpha
and beta
, with identical content.
如果我在master分支中删除alpha
,然后在我的功能分支中对其进行编辑,那么当我将master合并到Feature中时,会收到有关冲突的警告.假设我通过删除alpha
来解决此问题.
If I delete alpha
in my master branch, and edit it in my feature branch, then when I merge master into feature, I'm warned about a conflict. Assume I resolve this by deleting alpha
.
如果我随后使用git rebase master
将特征分支重新建立到主节点上,则会删除alpha
,但是现在我在特征分支上对alpha
所做的更改现在将应用到beta
!我收到冲突警告,但通过自动合并很高兴地解决了这一问题,而提交没有被阻止以供我查看.
If I then rebase my feature branch onto master using git rebase master
, alpha
is deleted, but the changes I made to alpha
on the feature branch are now applied to beta
! I get a conflict warning but it's happily resolved with an auto-merge without the commit being blocked for me to review.
有趣的是,如果我执行git rebase -i
并且只接受默认值,则不会编辑beta
,并且可以解决合并时解决的相同冲突.
Interestingly, if I do a git rebase -i
and just accept the default, beta
isn't edited and I get to resolve the same conflict I resolved at merge time.
然后是三个相关的问题:
Three related questions then:
- 为什么Git认为我对一个文件所做的更改应该应用于另一个文件,而另一个文件却没有通过提交进行编辑?
- 如何避免这种情况?
- 即使我采用默认选项,为什么对于交互式rebase而言,行为也会有所不同?
我正在Win7的Cygwin上运行Git 1.7.9.我将解说词粘贴到pastebin 上,如果有人想自己查看详细信息,请在空白目录中以git init
开头(由于篇幅原因,我不在此发布).
I'm running Git 1.7.9 on Cygwin on Win7. I've put a transcript on pastebin showing this starting with a git init
in an empty directory, if anyone wants to see the details for themselves (I'm not posting it here due to length).
推荐答案
-m
--merge
使用合并策略进行基础调整.使用递归(默认)合并策略时,这可使重新配置知道上游侧的重命名.
-m
--merge
Use merging strategies to rebase. When the recursive (default) merge strategy is used, this allows rebase to be aware of renames on the upstream side.
删除文件后,Git会认为该文件是重命名的候选文件,并尝试将基于基础的修补程序应用于相应的重命名文件.听起来可能对您的情况没有很好的猜测.
When a file is deleted, Git considers that a candidate for a rename, and tries to apply the rebased patch to the corresponding renamed file. It sounds like it might have made a poor guess in your case.
您可以使用-m
选项选择其他合并策略.例如,resolve
合并策略可以通过自动检测重命名来避免此问题(请参见 git-merge
(有关合并策略的详细信息).
You can use the -m
option to select a different merge strategy. For example, the resolve
merge strategy may avoid this problem with auto-detecting renames (see git-merge
for details on merge strategies).
这篇关于合并后关于被删除的文件感到困惑的Git rebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!