The Documentation does not state why .orig
files are created by default. Also, their content after the next merge is undefined. Still, there must be some reason for having them created by default.
My best guess is that correcting a failed merge is common and also easier when existing .orig
files are present (as opposed to repeating the merge) but apparently most users do not know what to do with them.
It's not that they are created by default, but rather that they are left behind by default. The git mergetool
command always copies the conflict-marker-ized file to a .orig
before running the command you selected as the merge tool.
The real reason the git mergetool
command creates them is so that it can compare the date stamp on the supposedly-merged file to the date stamp on the .orig
file it recently created.
Suppose the command that git mergetool
ran, that supposedly merged the three base, local (HEAD
/ --ours
), and remote (--theirs
) files, actually did nothing at all. For instance, suppose you chose the command true
, which is a no-op that simply succeeds. In this case, the "merged" file, which the command did not write-to, has the same time stamp it had when git mergetool
made it. Meanwhile the .orig
file also has the same time stamp it had when git mergetool
made it. This indicates to git mergetool
that the merge-tool you chose actually failed, and the file is not actually merged after all. If the supposedly-merged file is newer than the .orig
file, though, then the command you selected must have written to the file, so it's probably merged the way you want, now.
(The git mergetool
command has a separate configuration knob, "trust exit code", that is also intended for the same purpose: to try to decide whether the tool actually did merge the files. It uses both of these tricks to decide whether to run git add
. For merge tools that git mergetool
knows about, it has a built-in "trust exit code" setting. Obviously, the true
command is a terrible merge tool and is not built in.)
If we modify the question to read: Why does git mergetool
leave the .orig
file behind by default? then we have to ask the authors of git mergetool
why they chose that as the default. Only they actually know. We can speculate: perhaps it is because git checkout -m
, which can re-create the conflicts if the merge is still going on, did not exist as a command at the time. Perhaps it is because they thought this was the more convenient default: it's easier to rm *.orig
than it is to run git checkout -m
. But the truth is, I don't really know for sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With