当两个分支不同但在任一分支中没有新提交时,为什么不合并更改? [英] Why doesn't git merge changes when two branches are different but with no new commits in either branch?

查看:194
本文介绍了当两个分支不同但在任一分支中没有新提交时,为什么不合并更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

我的主分支里有东西。另一个名为 other_branch 的分支在其中包含stuff + more_stuff。每个分支都没有提交。



如果我签出master,然后尝试合并other_branch,git会说已经是最新的。并没有任何事情发生。为什么在这种情况下more_stuff不会被合并到master中?注意:other_branch是从一个较老的master的提交中创建的。

这是git是如何设计的? 解决方案

非常简单。如果git说已经最新,这意味着分支机构没有分歧。如果至少有一个分支包含另一个分支没有提交的提交,那么两个分支已经发生分歧。



我不确定你的意思是什么东西+ more_stuff在里面。如果你已经向other_branch添加了新文件(或者改变了现有文件),并且使用了git add和git commit,那么other_branch历史记录将与主分支不同。因为git说没有合并的改变,所以历史在那个分支上没有改变,即你没有提交任何东西。


For example,

I my master branch has stuff in it. Another branch called other_branch has stuff+more_stuff in it. Each branch has nothing to commit.

If I checkout master then try to merge other_branch, git says "Already up-to-date." and nothing happend. why won't more_stuff be merged into master in this case? Is that how git was designed?

NOTE: other_branch was created from an older commit of master.

解决方案

It's very simple. If git says "Already up-to-date" it means the branches have not diverged. 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. 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. Since git says that there are no changes to merge, the history hasn't changed on that branch, i.e. you haven't committed anything.

这篇关于当两个分支不同但在任一分支中没有新提交时,为什么不合并更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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