1

I have one file in master branch like belows:

void func(int a, string b) {
    ...
    if (a == 1) {
        ...
    }
    ...
}

....
func(1, "test");
...

Then I checkout a new branch b1, and do some work and change the file to :

void func(string c, string b) {
    ...

    ...
}

....
func("test", "test");
...

Meanwhile, the master branch has been updated by other guys, so i need to merge this branch (there's some reason i cannot rebase it). Since there's merge conflicts, i add the -X argument:

git merge -X ours master

It works, but with the deleted code segment:

void func(string c, string b) {
    ...
    if (a == 1) {
        ...
    } 
    ...
}

....
func("test", "test");
...

Did I miss some argument when merge?

Feiyu Zhou
  • 4,344
  • 32
  • 36
  • `-X ours` does not operate on a whole-file basis. See my answer here to a different question: http://stackoverflow.com/a/42104116/1256452 – torek Feb 14 '17 at 04:06

1 Answers1

1

since there's merge conflicts, i add the -X argument

It depends when you added the -X ours: you need to properly cancel your initial merge which had conflict (git merge abort), and check the state of your code before attempting a new merge with the -X ours merge option.
Then you can try again.

And you need to make sure that deleted code was on the same lines as your own code (which would mean conflict, if said deleted code was modified by new versions in master): -X ours only works in case of a conflict for those lines.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yes, i tried "git merge master" first, and got conflict. Since the current branch's code is what i need, i add the -X ours. The problem is that the deleted code is still there. The deleted code was not modified by the master branch, but there's something else modified in the same file. – Feiyu Zhou Feb 14 '17 at 05:59
  • @FeiyuZhou True, but you need to cancel your merge first, then try again with the -X ours. – VonC Feb 14 '17 at 06:00
  • @FeiyuZhou Then that part must not have been involved in conflict. – VonC Feb 14 '17 at 06:17
  • Yes the deleted part is not in conflict. But after i run the “git merge -X ours master” in order to solve the conflict which i does not want to solve it manually, the deleted part is not being delete as expect. – Feiyu Zhou Feb 14 '17 at 06:29
  • If the deleted part is not in conflict, the -X ours merge option would not change anything regarding that specific part. – VonC Feb 14 '17 at 06:34