Question

It seems I overestimated my knowledge of git.

A week ago I started working on a project. I downloaded it from server and started doing usual workflow with git.

A few days later a client notified me that he decided to introcuded some "improvements" into his code. He is not programmer but anyway he wants to add some changes. So it's not option to learn him how to use git.

At first I thought that I would just download his code from server (I didn't upload any code to his server), create a new branch from it and merge it with my code.

So, what I did: I created a new branch being in master( where my code is) -

 git branch client_branch
 git checkout client_branch

Then I deleted all my code from the project's folder and inserted only client's code.

I made a new commit in client_branch -

git commit -m clients_changes

Then for safety I did:

git checkout master
git branch merging
git checkout merging

and in the end:

  git merge client_branch

It went fine. I got no conflicts. But I bet that there must be conflicts. Because now I got not working version of code and all my changes disappeared in some files completely.

Please help, is it possible somehow to save his and mine changes?

Thanks in advance.

Was it helpful?

Solution 2

Ok, problem is solved.

After playing for a long time with git diff and looking how different versions of our code were I realised that it would be too tedious to do it via console.

The core of the problem can be represented so:

File A (mine):
The first line

File B(client's):

The 
second
line

If I do simple "git merge" command, independent in which branch I'm staying, I will get as result either first or second version of file. But I need to be warned about every difference! Because I cannot say for sure which version is better.

The situation got even worse, because I used code formatter, which formatted code to make it look better (actually a good thing but in this case it played a bad joke).

So I came to usage of kdiff3 utility:

enter image description here

It allowed me manually to see differences between every file and to decide whether I want to merge or not.

I must admit that it shouldn't be advised to get into such situations. But it happened so and I didn't find any better solution.

Hope it helps someone.

OTHER TIPS

The key to your problem is to find the revision that your client used to make his changes. Let's say he used revision X

git branch client_changes X
git checkout client_changes
# Apply client changes
git branch merging master
git checkout merging
git cherry-pick client_changes # Apply the changes by the client
# Verify the changes

This way you can just apply the changes from your client to your version. But it is crucial that you find the base revision your client used, or at least as close as you can or else you undo your own changes when you overwrite your code with your clients code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top