Py学习  »  Git

Git合并冲突对我来说毫无意义

Matt • 2 年前 • 547 次点击  

我有一个Git回购的降价文章,人们创建拉取请求(每个降价文章一个),最终合并到 master 然后,直接在 主人 ,我把那篇文章放到一个名为 字斟句酌 承诺并推动 主人 .

我有一个非常古老的请求,它仍然存在于一个叫做 home-base ,由一个文件组成 丹/homebase。医学博士 我正在考虑通过更多的提交将其编辑成型,然后合并到 主人 .

本垒 分支是 所以 从回购协议的角度来看,它与今天的情况完全不同 主人 .所以我认为反向合并可能会更好 主人 进入 本垒 只是为了让它更具时代感,并将合并基础提升很多。

但当我尝试这样做时,我会遇到一个我无法理解的合并冲突。


为了向你们展示情况,我要展示 ls 在每个分支中,文件和文件夹的数量都是这样的。我先从 主人 :

$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean

$ ls -1 -R
README.md
dan
instructions.md
wordpressed

./dan:

./wordpressed:
AppDelegateRefactor.md
BareListContentView.md
CellContentConfiguration.md
ControlTargetActioniOS14.md
GetStartedWithPods.md
MultipleTrailingClosures.md
StatesAndBackgrounds.md
Swift52notes1.md
Swift52notes2.md
Swift52notes3.md
UserInteractiveCells.md
bdd-common-pitfalls.md
bdd.md
brantsMenuBar.md
collectionViewContentConfig.md
collectionViewLists.md
collectionViewLists2.md
collectionViewOutline.md
debuggingLinks.md
diffableDataSources.md
diffableDataSources2.md
forwardCompatibity.md
haptics.md
iOS13deprecations.md
images
inAppPurchases.md
logging.md
miscSwiftTricks1.md
miscSwiftTricks2.md
miscSwiftTricks3.md
miscSwiftTricks4.md
multipleSelection.md
mysteriesOfLayout.md
newInIOS14.md
packages.md
photoPicker.md
protocolParadox.md
splitViewControllers.md
splitViewControllers2.md
swiftTrickTwoClasses.md
targetActionRant.md
typescript-shape-of-things.md
untappableButton.md
what-vs-how.md
xcode12Editing.md
xcode12testing.md
xcodeWhereAmI.md
xcodeWorkInTwoPlaces.md

./wordpressed/images:
argumentsInScheme.png
bigFlags.png
callHierarchy.png
callersMenu.png
chooser.png
config.png
createdTester.png
dataOrUrl.png
ipadportraitoverlay.png
listOfPepBoys.png
listWithSectionHeaders.png
littleFlags.png
looksLikeADuck.png
newTester.png
outlineIndicatorsWrong.png
outlineIndicatorsWrong2.png
perfectAfterHack.png
pickAPeppa.png
rootOnly.png
sandboxAccountOnDevice.png
selfSizingStringDrawer.png
simpleList.png
split1.png
split2.png
splitViewControllerPadLandscape.png
tableViewAsChoice.png
threecolumns.png
twoPossibilities.png
twoscreensphone.png
variableRowHeights.png
workingOutline.png

如您所见,主文件夹本身基本上是空的。所有的文章都在里面 字斟句酌 ,以及他们在 文字/图片 .


好了,现在是 本垒 :

$ git switch home-base
Switched to branch 'home-base'
Your branch is up to date with 'origin/home-base'.

$ ls -1 -R
GetStartedWithPods.md
README.md
Swift52notes1.md
Swift52notes2.md
Swift52notes3.md
dan
debuggingLinks.md
images
logging.md
miscSwiftTricks1.md
miscSwiftTricks2.md
miscSwiftTricks3.md
miscSwiftTricks4.md
packages.md
wordpressed
xcode12Editing.md
xcode12testing.md
xcodeWhereAmI.md
xcodeWorkInTwoPlaces.md

./dan:
bdd.md
homebase.md

./images:
chooser.png
config.png
split1.png
split2.png

./wordpressed:
images

./wordpressed/images:

正如你所见,这是一个更早的情况。没有任何东西被转移到 字斟句酌 然而有几篇文章漂浮在顶层 folder有两篇文章,包括我感兴趣的那篇, Homebase医学博士 .


最后,为了完整起见,我将向您展示 主人 本垒 :

$ git merge-base master home-base
b5d7355fe42eddad96beb200df2cba65381c288a
$ git checkout b5d7355fe
$ ls -1 -R
GetStartedWithPods.md
README.md
Swift52notes1.md
Swift52notes2.md
Swift52notes3.md
dan
debuggingLinks.md
images
logging.md
miscSwiftTricks1.md
miscSwiftTricks2.md
miscSwiftTricks3.md
miscSwiftTricks4.md
packages.md
wordpressed
xcode12Editing.md
xcode12testing.md
xcodeWhereAmI.md
xcodeWorkInTwoPlaces.md

./dan:
bdd.md

./images:
chooser.png
config.png
split1.png
split2.png

./wordpressed:
images

./wordpressed/images:

看起来很像 本垒 现在看来,不是吗?主要区别在于,这是以前的事 Homebase医学博士 出现在 文件夹


好吧。问问自己,当我尝试合并时会发生什么 主人 进入 本垒 .合并双方的贡献是什么?在我看来,Git应该意识到这一点 主人 许多新文件出现在 字斟句酌 ,其中一些是以前处于顶层的文件的重命名。当然,还有 本垒 ,一个新文件 Homebase医学博士 出现在 .

(在我看来)这些贡献不应该相互冲突。

好吧,让我们试试。

$ git switch home-base
$ git merge master
CONFLICT (file location): dan/homebase.md added in HEAD inside a directory that was renamed in master, suggesting it should perhaps be moved to wordpressed/homebase.md.
Automatic merge failed; fix conflicts and then commit the result.

$ git status
On branch home-base
Your branch is up to date with 'origin/home-base'.

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Changes to be committed:
    deleted:    dan/homebase.md
    new file:   instructions.md
    new file:   wordpressed/AppDelegateRefactor.md
    new file:   wordpressed/BareListContentView.md
    new file:   wordpressed/CellContentConfiguration.md
    new file:   wordpressed/ControlTargetActioniOS14.md
    renamed:    GetStartedWithPods.md -> wordpressed/GetStartedWithPods.md
    new file:   wordpressed/MultipleTrailingClosures.md
    new file:   wordpressed/StatesAndBackgrounds.md
    renamed:    Swift52notes1.md -> wordpressed/Swift52notes1.md
    renamed:    Swift52notes2.md -> wordpressed/Swift52notes2.md
    renamed:    Swift52notes3.md -> wordpressed/Swift52notes3.md
    new file:   wordpressed/UserInteractiveCells.md
    new file:   wordpressed/bdd-common-pitfalls.md
    renamed:    dan/bdd.md -> wordpressed/bdd.md
    new file:   wordpressed/brantsMenuBar.md
    new file:   wordpressed/collectionViewContentConfig.md
    new file:   wordpressed/collectionViewLists.md
    new file:   wordpressed/collectionViewLists2.md
    new file:   wordpressed/collectionViewOutline.md
    renamed:    debuggingLinks.md -> wordpressed/debuggingLinks.md
    new file:   wordpressed/diffableDataSources.md
    new file:   wordpressed/diffableDataSources2.md
    new file:   wordpressed/forwardCompatibity.md
    new file:   wordpressed/haptics.md
    new file:   wordpressed/iOS13deprecations.md
    new file:   wordpressed/images/argumentsInScheme.png
    new file:   wordpressed/images/bigFlags.png
    new file:   wordpressed/images/callHierarchy.png
    new file:   wordpressed/images/callersMenu.png
    renamed:    images/chooser.png -> wordpressed/images/chooser.png
    renamed:    images/config.png -> wordpressed/images/config.png
    new file:   wordpressed/images/createdTester.png
    new file:   wordpressed/images/dataOrUrl.png
    new file:   wordpressed/images/ipadportraitoverlay.png
    new file:   wordpressed/images/listOfPepBoys.png
    new file:   wordpressed/images/listWithSectionHeaders.png
    new file:   wordpressed/images/littleFlags.png
    new file:   wordpressed/images/looksLikeADuck.png
    new file:   wordpressed/images/newTester.png
    new file:   wordpressed/images/outlineIndicatorsWrong.png
    new file:   wordpressed/images/outlineIndicatorsWrong2.png
    new file:   wordpressed/images/perfectAfterHack.png
    new file:   wordpressed/images/pickAPeppa.png
    new file:   wordpressed/images/rootOnly.png
    new file:   wordpressed/images/sandboxAccountOnDevice.png
    new file:   wordpressed/images/selfSizingStringDrawer.png
    new file:   wordpressed/images/simpleList.png
    renamed:    images/split1.png -> wordpressed/images/split1.png
    renamed:    images/split2.png -> wordpressed/images/split2.png
    new file:   wordpressed/images/splitViewControllerPadLandscape.png
    new file:   wordpressed/images/tableViewAsChoice.png
    new file:   wordpressed/images/threecolumns.png
    new file:   wordpressed/images/twoPossibilities.png
    new file:   wordpressed/images/twoscreensphone.png
    new file:   wordpressed/images/variableRowHeights.png
    new file:   wordpressed/images/workingOutline.png
    new file:   wordpressed/inAppPurchases.md
    renamed:    logging.md -> wordpressed/logging.md
    renamed:    miscSwiftTricks1.md -> wordpressed/miscSwiftTricks1.md
    renamed:    miscSwiftTricks2.md -> wordpressed/miscSwiftTricks2.md
    renamed:    miscSwiftTricks3.md -> wordpressed/miscSwiftTricks3.md
    renamed:    miscSwiftTricks4.md -> wordpressed/miscSwiftTricks4.md
    new file:   wordpressed/multipleSelection.md
    new file:   wordpressed/mysteriesOfLayout.md
    new file:   wordpressed/newInIOS14.md
    renamed:    packages.md -> wordpressed/packages.md
    new file:   wordpressed/photoPicker.md
    new file:   wordpressed/protocolParadox.md
    new file:   wordpressed/splitViewControllers.md
    new file:   wordpressed/splitViewControllers2.md
    new file:   wordpressed/swiftTrickTwoClasses.md
    new file:   wordpressed/targetActionRant.md
    new file:   wordpressed/typescript-shape-of-things.md
    new file:   wordpressed/untappableButton.md
    new file:   wordpressed/what-vs-how.md
    renamed:    xcode12Editing.md -> wordpressed/xcode12Editing.md
    renamed:    xcode12testing.md -> wordpressed/xcode12testing.md
    renamed:    xcodeWhereAmI.md -> wordpressed/xcodeWhereAmI.md
    renamed:    xcodeWorkInTwoPlaces.md -> wordpressed/xcodeWorkInTwoPlaces.md

Unmerged paths:
  (use "git add <file>..." to mark resolution)
    added by us:     wordpressed/homebase.md 

好的,最后一行是我不明白的。“由我们添加”是什么意思 wordpressed/homebase。医学博士 ? 这不是我们添加它的地方。我们把它加进去了 .

也不 主人 也没有 本垒 有档案吗 wordpressed/homebase。医学博士 .那么Git是从哪里得到这个想法的呢???这似乎与它认为存在合并冲突的原因有关:

丹/homebase。医学博士 在HEAD中添加了一个在master中重命名的目录,这表明它可能应该被移动到wordpressed/homebase。医学博士。

所以: Git在说什么? Git为什么这么想 丹/homebase。医学博士 应该是 wordpressed/homebase。医学博士 没有我能找到的证据?如何防止这种合并冲突,并让Git对此更加简单化?我可以使用不同的合并策略吗?或者,我怎么能简单地解决冲突,说“不,吉特,走开”呢 丹/homebase。医学博士 一个人,好吗?

再次为问题中的细节长度道歉。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129957
 
547 次点击  
文章 [ 1 ]  |  最新文章 2 年前
torek
Reply   •   1 楼
torek    3 年前

这一特殊冲突:

CONFLICT (file location): dan/homebase.md added in HEAD inside a
directory that was renamed in master, suggesting it should perhaps
be moved to wordpressed/homebase.md.

是Git中一项相对现代的发明。Git现在试图找到 目录重命名 在合并基本提交和每个提示提交之间。也就是说,已经跑了 git diff --find-renames <base> <left> git diff --find-renames <base> <right> ,它在左侧检测到一些重命名,在右侧检测到一些重命名(总数为正数)。至少其中一些重命名意味着目录名的更改。所以Git现在认为 另外 合并的一侧应该应用相同的目录名更改。

(大约在2.19世纪中期,Git的预发布版本添加了各种实验版本的代码,我忘记了它何时真正稳定下来。仔细阅读发行说明,看起来2.17就是它发布的时候,然后在2.19中修复了一个后续的角落案例。)

[Edit,2021年4月15日:]当这项新功能投入使用时,一个新的控制旋钮也投入使用: merge.directoryRenames .其默认值为 conflict ,但您可以将其设置为 true (意思是总是做出它已经做出的假设,但不要称之为冲突)或 false (意思是永远不要做出新的假设,因此不要称之为冲突)。

这是Git宣布的唯一冲突,因此它是最后一个“未合并文件”部分显示的唯一文件:

Unmerged paths:
  (use "git add <file>..." to mark resolution)
    added by us:     wordpressed/homebase.md

Git在这方面采纳了自己的内部建议:它认为,一切都会增加 dan/ 在合并基和 HEAD 应该被添加到 wordpressed/ 因为它看到了合并基部和顶部之间的变化 master .

如果您觉得这是正确的,Git希望您通过运行 git add 在那个路径名上。如果没有,Git希望您将文件移动到您认为应该去的任何地方 git添加 结果(并移除,使用 git rm 或者是 git添加 ,Git使用的名称)。