I apologise if this has been answered somewhere thoroughly, obvious and many times as it likely already has; but I've been unable to find information on this specific problem I'm having after searching for at least a week.

To simplify we have 3 people working on a project, each person has their own branch which we are regularly going to merge back into the master trunk. The problem is that we either get conflicts (attempting to cherry pick) or it simply seems to overwrite all the files of the master and the first 2 branches merged with the last one, effectively merging nothing, just overwriting.

My problem is (hopefully) simply:

Master trunk

string test1;
string test2;
string test3;

test1 branch

 string test1 = "Dan Branch merged";
 string test2;
 string test3;

test2 branch

string test1;
string test2 = "Dave Branch merged";
string test3;

test3 branch

string test1;
string test2;
string test3 = "Will Branch merged";

Desired output when all 3 branches are merged:

string test1 = "Dan Branch merged";
string test2 = "Dave Branch merged";
string test3 = "Will Branch merged";

What I actually get when I try to merge test 1 and 2 is:

Automatic merge failed; fix conflicts and then commit the result.

  <<<<<<< HEAD
 +        String test1 = "Dan Branch merged";
 +        String test2;
 +        String test3;
  =======
+         String test1;
+         String test2 = "Dave Branch merged.";
+         String test3;
  >>>>>>> test2

I am currently using git-gui on Windows (with the plan of changing to the bash/shell/cli when I've finally got my head around git) so if it all possible it'd be great if any answers were given specifically for git-gui, but of course beggars can't be choosers.

Trying to keep things simple the repository is on a local network folder and not any server. I don't know if this affects the implementation (I'd imagine push and pull would be unused if I've guessed their usage correctly)

Currently Git has been relegated to just being a method to store and browse old versions as all merging is being done by hand.

有帮助吗?

解决方案

The way you handle your code might not be the regular way to handle distributed developing. I'd recommend (if access to master trunk is available during developing) the following steps to make this work:

git stash     (to put your changes away for the moment)
git pull      (to get the latest commits)
git stash pop (to get back, what was stashed away in the first step)

Then resolve the conflict you have. This should be not as much as when merging a whole branch. Then:

git commit
git push

Important: Avoid changing the branch and work on master. Branches are more often used to develop things in parallel, that aren't commited every day to master. E.g. when starting a new, major version of a software, that changes much of the old code or api, so that you can't simply push them to master, because the commit would unstabilize the whole package.

Edit:

To honorate David's comment: It's no harm in using branches in git, but I had one or two cases, where unproperly handled branches lead to confusions, that an unexperienced git user had a hard time to understand and resolve. Those handling mistake shouldn't be usual, though.

Edit:

As it turns out you really do have only one local repository alltogether. It seemed to me, that you have a LAN repository you all push to, at first. So if you don't change your infrastructure (I don't recommend it. An alternative would be http://bitbucket.org and everyone with his own repository clone on his computer) then there is (I think) no other way then in having three branches. I strongly recommend to you, that you read a git tutorial like http://www.vogella.com/articles/Git/article.html in order to change your infrastructure. Good Luck with it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top