gitvisual-studio-codemerge

Visual Studio Code, fully manual merge?


I merged two branches and the resulting code crashed. I did a git diff and studied it carefully. Now I would like to go back and use the VSCode merge tool to do a fully manual merge of these two branches: to manually visit every single difference and make the decision which to use, as if they were all merge conflicts. Is there any way to invoke this?


Solution

  • You can't easily do what you're asking, but you can get close. It's possible to do this:

    manually visit every single difference and make the decision which to use,

    but not necessarily this part:

    as if they were all merge conflicts

    Essentially, you need to repeat the merge, and inspect the changes before committing. Every merge commit has (at least) 2 parents. When you're viewing git log, a merge commit will look like this:

    commit abcd0002b1adcdd9085f59dac7c8bff9714499e9
    Merge: 1234abcd 2345bcde
    

    In this case, 1234abcd is the first parent of the merge commit, and 2345bcde is the second parent. To repeat the merge, checkout the first parent and merge in the second parent, but don't commit it yet:

    git switch --detach 1234abcd
    git merge 2345bcde --no-commit
    

    Note if there are any merge conflicts you don't even need --no-commit because it will pause anyway.

    Now you can use your favorite editor (VSCode) for viewing the pending merge. Simply inspect all of the staged changes to make sure they are what you expect. (For large merges this can be extremely time consuming!)

    For any of the merge conflicts, you can re-do those as desired.

    When finished, either git merge --continue or git commit.