Which version of the git file will be finally used: LOCAL, BASE or REMOTE?

前端 未结 8 1424
故里飘歌
故里飘歌 2020-11-28 17:39

When there\'s a collison during git merge, I open a mergetool called Meld. It opens three files LOCAL, BASE and REMOTE. As I\'ve read LOCAL is my local branch,

8条回答
  •  情深已故
    2020-11-28 18:16

    There are 4 files involved:

    1. $LOCAL The file on the branch where you are merging; untouched by the merge process when shown to you

    2. $REMOTE The file on the branch from where you are merging; untouched by the merge process when shown to you

    3. $BASE The common ancestor of $LOCAL and $REMOTE, ie. the point where the two branches started diverting the considered file; untouched by the merge process when shown to you

    4. $MERGED The partially merged file, with conflicts; this is the only file touched by the merge process and, actually, never shown to you in meld


    The $MERGED file is the one that contains the <<<<<<, >>>>>>, ===== (and, maybe, ||||||) markers (that delimit conflicts). This is the file that you edit manually to correct conflicts.

    The manual conflicts editing and the visual conflicts editing are done on different files and presented different informations.

    When using the mergetool (assume meld), the files that are seeing therein are: $LOCAL, $BASE, $REMOTE. Note that you don't see the $MERGED file, although this is passed as a hidden parameter to meld to write the result of the edit there.

    In other words, in meld, you are editing the file in the middle, the $BASE file, and you pick all the changes from left or from the right manually. It is a clean file, not touched by the merge process. The only glitch is that, when you save, you do not save into the $BASE file, but in the fourth hidden parameter of meld, that is the $MERGED file (that you do not even see). The $BASE file does not contain any conflicts or partial successful merges because it is not the $MERGED file.

    In the visual editing, when presenting to you the $BASE file (instead of the $MERGED file) git basically discards all its attempts to do the merging (those attempts are visible, if you want, in the $MERGED file) and lets you to completely do the merging from scratch.

    The bottom line is that in manual and visual merging conflicts you are not looking at the same files, but the final result is written in the same file (that is the $MERGED file).

    The manual correction of the conflicts is done on $MERGED because git has no mean to present you three files, so it squashes the information from the three files ($LOCAL, $BASE, $REMOTE) in that $MERGED file.

    But the visual tools have the means to show you three files: they show you the $LOCAL, $BASE, $REMOTE files. You are picking changes from the $LOCAL and $REMOTE files and you are bringing those into the $BASE file, completely re-building and even overwriting the failed attempt of merging that is the $MERGED file.

提交回复
热议问题