合并后2个分支之间的差异:GIT [英] Differences between 2 branches after merge: GIT

查看:475
本文介绍了合并后2个分支之间的差异:GIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在第二个分支NC12-changePassword上工作.

master分支进行了更改,该分支可以处理字符串的解密.我需要这些新更改才能在我的分支上实现新功能,所以我合并了这些更改.

我做了一个git pull,没有冲突.当我运行git log时,它显示合并提交.另外,当我运行git merge master时,它会告诉我所有内容都是最新的.

但是我的代码不起作用,当我运行git diff NC12-changePassword master时,它列出了master中的内容而不是NC12-changePassword中的内容.这对我来说没有意义,因为我已经合并了更改,因此master中的所有内容都应该在NC12-changePassword中.

我的理解是我的分支应该像master一样工作,并且代码应该可以正常工作.还是我错过了某事:-\.

解决方案

,因此主服务器中的所有内容都应在NC12-changePassword中

这不是合并"的意思,因此也不是git merge的意思.

让我们举一个非常简单的例子进行说明.假设您从master分支创建了一个分支,并且作为该分支的一部分甚至全部分支,您删除了一段代码并提交了结果.

然后,在您完成上述操作之后,假设Fred修改了master以添加第二个代码块-也许完全在另一个文件中-仅在第一个代码块存在的情况下才有用.他将其提交给master.

后来,您在master中获得了Fred的工作,并使用git merge将他的零钱转为母版带入您的分支机构. Git将放回您删除的代码:假设您知道自己当时在做什么.它所要做的只是发现Fred添加了一个 new 代码块,并将其添加到您的分支中,该分支什么也不做,因为它取决于您删除的代码块.

如果现在将分支与Fred的master进行比较,您仍将具有已删除的代码块:已删除的代码块.您不会在master中拥有所有. (您自己的master可能也不会进行Fred的更改,因为在上面,我们从未提及您开始使用您的 master并从他的master中引入他的更改. )

在复杂的情况下,您必须使用自己的知识(将始终超过git的知识)来修复语义上不正确的合并. Git最多会注意到语法冲突,例如:嘿,您删除了此代码块,但是Fred对该代码块进行了更改,因此由于git我一无所知,因此您必须解决这个问题冲突".但这仅在您有幸发生句法冲突的情况下才会发生.如果尽管所做的更改,Fred的更改都适合",但由于更改而没有执行任何操作,则git甚至不会注意到这一点.

I am currently working on a second branch called NC12-changePassword.

There have been changes made to master branch which handle decrypting of a string. I required these new changes to be able to implement a new feature on my branch so I merged the changes.

I did a git pull and there were no conflicts. When I run git log it shows the merge commit. Also when I run git merge master it tells me everything is up to date.

However my code is not working and when I run git diff NC12-changePassword master it lists what's in master that isn't in NC12-changePassword. This doesn't make sense to me because I have merged the changes and therefore the everything that is in master should be in NC12-changePassword.

My understanding is that my branch should function like master and the code should work fine. Or am I missing something :-\ .

解决方案

and therefore the everything that is in master should be in NC12-changePassword

That's not what "merge" means, and therefore not what git merge does.

Let's take a very simple example for illustration. Suppose you made a branch off master and, as part or even all of that branch, you deleted a block of code and committed the result.

Then, after you've done that, suppose Fred modifies master to add a second block of code—perhaps in a different file entirely—that only does something useful if the first block of code exists. He commits that to master.

Later, you obtain Fred's work in master and use git merge to bring his-changes-to-master into your branch. Git will not put back the code you deleted: it assumes you knew what you were doing then. All it will do is discover that Fred added a new block of code, and it will add that same block to your branch, where it does nothing because it depends on the block you deleted.

If you now compare your branch to Fred's master, you will still have a deleted block of code: the block you deleted. You won't have everything that's in that master. (Your own master will probably not have Fred's changes either, because in the above, we've never mentioned you getting on to your master and bringing in his changes from his master.)

In complicated situations, you must use your own knowledge (which will always exceed git's) to fix up merges that are semantically incorrect. Git will, at most, notice syntactic collisions, things like: "hey, you deleted this block of code, but Fred made a change to that same block, so since I, git, know nothing of semantics, you will have to resolve this conflict". But this happens only if you are lucky enough to have a syntactic conflict. If Fred's changes "fit in" despite your changes, but do nothing because of your changes, git won't even notice that.

这篇关于合并后2个分支之间的差异:GIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆