Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-merge

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.

like image 999
trusktr Avatar asked Mar 19 '12 00:03

trusktr


1 Answers

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.

like image 103
ralphtheninja Avatar answered Sep 17 '22 22:09

ralphtheninja