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

风格不统一 提交于 2020-01-14 09:01:31

问题


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.


回答1:


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.




回答2:


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.

You can use gitk to check the visual tree of your branches.



来源:https://stackoverflow.com/questions/9763443/why-doesnt-git-merge-changes-when-two-branches-are-different-but-with-no-new-co

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!