-1

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?

vico
  • 17,051
  • 45
  • 159
  • 315
  • Not have used Meld yet but what about that answer? https://stackoverflow.com/questions/50812907/git-meld-how-to-keep-both-changes-during-merge – Jonas Oct 03 '21 at 20:18

1 Answers1

1

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141