tags:

views:

48

answers:

2

I have inherited some code (from zip file) from a developer and git initialzed, made changes and set of check-ins progressively.

Now, the same developer released the same code with his changes and gave me the another zip file.

How do i merge my changes which i have it my git repo and his recent changes from the second zip file contents?

Ideally, i would like to have the code which should be accumalation of both my changes and the developer recent changes.

I tried to create branch b1 from my master branch and applied second zip file contents on top of that. committed those files in the branch and did 'git checkout master; git merge b1' - but, i do not get my changes, only his changes in my master branch.

+3  A: 

It sounds like both you and the other based your work on the code that you have as the root commit in your repository. So right now you have this:

A - B - C - D (master)

The other developer's work is also based off of commit A. So, the proper place to commit it is off of A.

Start by creating and checking out a branch there: git checkout -b his_work <SHA1 of A> (or in gitk, just right click on the commit and choose create a branch).

Next, dump in his work, and commit it. To be nice, you can do this with git commit --author="His Name <his.email@somewhere>" to show that it was his work.

Now, check out your master (git checkout master) and merge his branch (git merge his_work).

You should end up with this:

A - B - C - D - E (master)
 \             /
  X -----------
  (his_work)

Just for the sake of explanation, here's what you did:

A - B - C - D      -      X (his_work)
         (master) ----> 

You committed his work on top of your most recent, then merged it; the merge was a fast-forward: since master was an ancestor of the branch you merged, you simply moved master forward to that new commit.

Jefromi
I was afraid that i was not clear in the question. thanks for clear answer. git rules.
neduma
+1  A: 

The reason you only got his changes is because your branch is based off of your most recent commit. You then replaced all your files with his, and committed it. Git sees this as a massive edit replacing your files with his, not a merge.

To get what you desire, you need to branch at the point where is changes split off from yours. It sounds like that is your first commit. So you can do:

git checkout <first-commit>
git checkout -b b1        // This just names the branch for the later merge
<copy his files from the zip in>
git checkout master
git merge b1

From here, git sees that b1 is based off of the first commit, so it views all changes from master since then as 'concurrent' changes, which is what you want.

bobDevil
Got it. thanks a lot.
neduma