简体   繁体   English

Git 在将要合并的同一分支的手动更新/提交之上自动合并

[英]Git automatic merge on top of maual update/commit from the same branch which is going to be merged

I have a branch A which i want to merge with branch B (updated), there have been some code/files commit to branch A manually from branch B .我有一个branch A ,我想与branch B合并(更新),已经有一些代码/文件从branch B手动提交到branch A Now i want to auto merge complete chages from branch B to A. I have below queries/doubts on this -现在我想自动合并从分支 B 到 A 的完整 chages。我对此有以下疑问/疑问 -

  1. When i tried to do automatic merge, git shows new code/files addition/update which are already present in branch A as part of manual update/commit previously done.当我尝试进行自动合并时,git 显示新的代码/文件添加/更新,这些新代码/文件添加/更新已经存在于branch A中,作为先前完成的手动更新/提交的一部分。
  2. Is it fine if go ahead and merge them, would there be code/file duplicacy?如果 go 提前合并它们可以吗,会有代码/文件重复吗?
  3. Or should i be doing manual merge?还是我应该进行手动合并? but there are lots of changes但是有很多变化

Give me chance to explain more if its not clear.如果不清楚,请给我机会解释更多。 Any help would be appreciated.任何帮助,将不胜感激。

This is probably going to end up fine, and Git will not produce duplicate code.这可能会很好,并且 Git 不会产生重复的代码。

When you do a merge, Git looks at the two heads (the branches you're merging), plus the merge base, which is usually the most recent common commmit.当您进行合并时,Git 会查看两个头(您正在合并的分支)以及合并基础,这通常是最近的常见提交。 If both heads have the exact same contents for a file, then the merge is trivial, and Git picks that result.如果两个头具有完全相同的文件内容,则合并是微不足道的,Git 选择该结果。 If they don't, it tries to incorporate the changes from each side.如果他们不这样做,它会尝试合并来自每一方的更改。

When it does this, if the changes are to two separate areas of code, the merge succeeds, because Git will include the change from each side.执行此操作时,如果更改是针对两个单独的代码区域,则合并成功,因为 Git 将包含来自每一方的更改。 If the changes are to the same area, but they're identical changes, then Git just takes that identical piece (once) and uses it in the result.如果更改是针对同一个区域,但它们是相同的更改,那么 Git 只需获取相同的部分(一次)并在结果中使用它。 If you have different changes to the same area, then Git will conflict and you'll have to resolve things manually.如果您对同一区域有不同的更改,则 Git 将发生冲突,您必须手动解决问题。

If the merge succeeds without conflicts, then Git will probably have done the right thing and you'll get a sane result, although sometimes merges do result in odd behavior because Git only operates on lines and doesn't intrinsically know about the structure of your code.如果合并成功而没有冲突,那么 Git 可能会做正确的事情,你会得到一个理智的结果,尽管有时合并确实会导致奇怪的行为,因为 Git 只在行上运行并且本质上不知道你的结构代码。 Usually you can detect this by building and testing your code, and in typical practice, unexpected behavior happens very rarely.通常,您可以通过构建和测试代码来检测到这一点,在典型的实践中,意外行为很少发生。 Git doesn't duplicate code if both sides have similar changes; Git 双方有类似变化时不重复代码; at worst, it conflicts and lets you figure out what to do.在最坏的情况下,它会发生冲突并让您弄清楚该怎么做。

If the merge has conflicts, you'll have to resolve them by hand.如果合并有冲突,您必须手动解决它们。 If you're doing the merge through GitHub using a pull request, it will tell you if there are conflicts or not in the pull request.如果您使用拉取请求通过 GitHub 进行合并,它将告诉您拉取请求中是否存在冲突。 If you're doing them on the command line, then you just have to try and see how it works out.如果您在命令行上执行它们,那么您只需要尝试看看它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM