The problem is that you created the code_to_integrate
branch on top of you master
branch. So things looked like this:
... -> oldercommit -> oldcommit -> c1 (master, code_to_integrate)
When you then committed the other guy's code to this branch you get a linear history:
... -> oldercommit -> oldcommit -> c1 (master) -> c2 (code_to_integrate)
When you now merged code_to_integrate
into master git detected that c2
is just newer than c1 and did a so called fast forward merge, which basically means only changing the commit
that master
points to to c2
. Imagine code_to_integrate
was just a quick branch you yourself made to do some work on, e.g. fix a bug. Once you are done you would have the exact same history and a fast forward merge would be precisely what you want.
In order to fix you problem you need to tell git which of you old commits is the newest common ancestor of your and the other guy's work. Basically you need to tell git at which point in time the other guy branched off your master
. You so that by checking which is newest commit that both you and the other guy have in your history and then starting the code_to_integrate
branch there. Assuming that the other guy branched off at oldercommit
, you would do a git checkout oldercommit
followed by a git checkout -b code_to_integrate
and should get something like this.
... -> oldercommit (code_to_integrate) -> oldcommit -> c1 (master)
Once you commit the other guy's version you get:
-> c2 (code_to_integrate)
/
... -> oldercommit -> oldcommit -> c1 (master)
When you now merge code_to_integrate
into master
, git will see that there is a divergent history and do a three-way merge (where oldercommit
is the mergebase), prompting you to resolve any conflicts that might arise, etc. This is what you want!
So in summary you simply started your code_to_integrate
branch from the wrong commit. There is no way git or any other version control system can do a merge without knowing what the mergebase is.
EDIT: If you did not share any changes with the other guy since you put the code into git, then your mergebase is the oldest commit in your history. The following should do what you want:
git checkout $(git rev-list --all | tail -n 1)
git checkout -b code_to_integrate
[ ... put the other guys code into your working directory and commit it ... ]
git checkout master
git merge code_to_integrate
The first command checks out the oldest commit in your history, which is the last one that you and the SVN guy have in common. The 2nd command creates the code_to_integrate
branch at your oldest commit and switches to it. Then you throw the other guys code into your working directory and commit it to the code_to_integrate
branch. Finally you switch back to your master
branch and merge the other branch in.