I want to know an exact algorithm (or near that) behind git merge
. The answers at least to these sub-questions will be helpful:
But the description of a whole algorithm will be much better.
You might be best off looking for a description of a 3-way merge algorithm. A high-level description would go something like this:
B
- a version of the file that is an ancestor of both of the new versions (X
and Y
), and usually the most recent such base (although there are cases where it will have to go back further, which is one of the features of git
s default recursive
merge)X
with B
and Y
with B
.The full algorithm deals with this in a lot more detail, and even has some documentation (https://github.com/git/git/blob/master/Documentation/technical/trivial-merge.txt for one, along with the git help XXX
pages, where XXX is one of merge-base
, merge-file
, merge
, merge-one-file
and possibly a few others). If that's not deep enough, there's always source code...