简体   繁体   English

当两个分支不同但两个分支中没有新的提交时,为什么git不会合并更改?

[英]Why doesn't git merge changes when two branches are different but with no new commits in either branch?

For example, 例如,

I my master branch has stuff in it. 我的主分支里面有东西。 Another branch called other_branch has stuff+more_stuff in it. 另一个叫做other_branch分支other_branch有东西+ more_stuff。 Each branch has nothing to commit. 每个分支都没有任何提交。

If I checkout master then try to merge other_branch, git says "Already up-to-date." 如果我签出master然后尝试合并other_branch,git说“已经是最新的”。 and nothing happend. 没有任何事情发生。 why won't more_stuff be merged into master in this case? 为什么在这种情况下不会将more_stuff合并为master? Is that how git was designed? 这是git的设计方式吗?

NOTE: other_branch was created from an older commit of master. 注意:other_branch是从较早的master提交创建的。

It's very simple. 这很简单。 If git says "Already up-to-date" it means the branches have not diverged. 如果git说“已经是最新的”,这意味着分支机构没有分歧。 Two branches have diverged if at least one of the branches contains a commit that the other branch doesn't have. 如果至少有一个分支包含另一个分支没有的提交,则两个分支已经分歧。

I'm not sure what you mean by has stuff + more_stuff in it. 我不确定你的意思是什么东西+ more_stuff在里面。 If you have added new files to other_branch (or changed existing files), and used "git add" and "git commit" other_branch history will have diverged from the master branch. 如果您已将新文件添加到other_branch(或更改现有文件),并使用“git add”和“git commit”,则other_branch历史记录将与主分支不同。 Since git says that there are no changes to merge, the history hasn't changed on that branch, ie you haven't committed anything. 由于git表示没有合并的更改,因此该分支上的历史记录没有变化,即您没有提交任何内容。

It only happens when the the branch you are trying to merge is already contained in the current branch. 它只发生在您尝试合并的分支已包含在当前分支中时。

So, the more_stuff you mentioned is already in the master branch. 所以,你提到的more_stuff已经在master分支中了。

You can use gitk to check the visual tree of your branches. 您可以使用gitk检查分支的可视树。

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

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