Merge two branches by using code from both of them

42 Views Asked by At

I have two branches master and i1:

Branch master:

int main() {
    std::cout << "Hello World!";
    std::cout << "1";
    std::cout << "3";
    std::cout << "5";
    return 0;
}

Branch i1:

int main() {
    std::cout << "Hello World!";
    std::cout << "1";
    std::cout << "2";
    std::cout << "4";
    std::cout << "6";
    return 0;
}

Got conflict while merging i1 to master :

int main() {
    std::cout << "Hello World!";
    std::cout << "1";
<<<<<<< HEAD
    std::cout << "2";
    std::cout << "4";
    std::cout << "6";
=======
    std::cout << "3";
    std::cout << "5";
>>>>>>> master
    return 0;
}

I do merge with Meld:

enter image description here

Meld offers only to choose master or i1. How to have both of them in result?

1

There are 1 best solutions below

0
matt On

You don't need Meld for this. Any text editor will do. You have the conflict expressed in your file:

int main() {
    std::cout << "Hello World!";
    std::cout << "1";
<<<<<<< HEAD
    std::cout << "2";
    std::cout << "4";
    std::cout << "6";
=======
    std::cout << "3";
    std::cout << "5";
>>>>>>> master
    return 0;
}

Just eliminate the merge conflict markers and arrange the code in the order you want it:

int main() {
    std::cout << "Hello World!";
    std::cout << "1";
    std::cout << "2";
    std::cout << "3";
    std::cout << "4";
    std::cout << "5";
    std::cout << "6";
    return 0;
}

Save, add, and commit.