Reputation: 10030
We are trying to merge a branch back into master and whenever we try it merges with no changes, there is nothing to push. The branch has several new classes and files master does not, and hundreds of changes to existing files that master does not have.
How can we get this to merge? If this is a typical issue, what are we doing wrong to cause this?
Upvotes: 2
Views: 661
Reputation: 98469
What you think of as "new files" and what git thinks may be different.
Imagine this situation: you create a file in a branch. You merge that branch to master
. Then you delete the file in master
with a new commit. Your history looks like this:
A ----------------B - E (delete file) - F (master HEAD) \ / C (add file) - D - G (branch HEAD)
Now, when you go to merge the G
into F
, what will happen? Not what you expected, because your master
history already includes the commit which added the file. But the file exists in G
, and not in F
! But from git's perspective, the only "new" change is G
.
A merge finds the most recent common ancestor of the branch(es) you're merging. It then fuses all the changes since then into the branch you're currently on. Any change made prior to that common ancestor is not re-merged. You can see what git thinks is the "merge base" with the git merge-base
command. In the above graph, it is B
.
I suspect you didn't actually want a merge, here. I think you probably wanted to cherry-pick some changes. A cherry pick will always apply a change, even if an identical one is already in your history.
This is a common problem, and the usual practice is to make changes flow one direction. If a branch pulls from master
, then the only time it merges back into master
is when it ends; after that final back-merge, no new commits are made to the branch. Most common workflows don't include two branches merging into one another and also having ongoing development on both sides.
Upvotes: 1
Reputation: 1031
You must be in the branch that you want to bring the changes.
In your case in master:
git checkout master
git merge yourBranch
If you are in yourBranch and try to merge in master, you get nothing because you already have all the changes of master.
Upvotes: 0