ArticleslgStudy

science

Merge (version control)

Merge (version control) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Merge (version control) rather than just read about it. In short: In version control, merging (also called integration) is a fundamental operation that reconciles changes made to a version-controlled collection of files. Most often, it is necessary when a file is modified on two independent branches and subsequently merged.

Merge (version control) — main illustration
Merge (version control) — illustration

Key takeaways

  • Merge (version control) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Merge (version control) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Merge (version control) from memory before moving on to harder problems.

Reference excerpt

In version control, merging (also called integration) is a fundamental operation that reconciles changes made to a version-controlled collection of files. Most often, it is necessary when a file is modified on two independent branches and subsequently merged. The result is a single collection of files that contains both sets of changes. In some cases, the merge can be performed automatically, because there is sufficient history information to reconstruct the changes, and the changes do not conflict. In other cases, a person must decide exactly what the resulting files should contain. Many revision control software tools include merge capabilities.

Types of merges There are two types of merges: unstructured and structured.

Unstructured merge Unstructured merge operates on raw text, typically using lines of text as atomic units. This is what Unix tools (diff/patch) and CVS tools (SVN, Git) use. This is limited, as a line of text does not represent the structure of source code.

Structured merge Structured merge tools, or AST merge, turn the source code into a fully resolved AST. This allows for a fine-grained merge that avoid spurious conflicts.

Workflow Automatic merging is what version control software does when it reconciles changes that have happened simultaneously (in a logical sense). Also, other pieces of software deploy automatic merging if they allow for editing the same content simultaneously. For instance, Wikipedia allows two people to edit the same article at the same time; when the latter contributor saves, their changes are merged into the article instead of overwriting the previous set of changes. Manual merging is what people have to resort to (possibly assisted by merging tools) when they have to reconcile files that differ. For instance, manual merging will be used if two systems have slightly differing versions of a configuration file and a user requires changes from both versions of the system. Obtaining the required changes can usually be achieved by merging the configuration files through a manual process of picking the wanted changes from both sources (this is also called two-way merging). Manual merging is also required when automatic merging runs into a change conflict, aka a merge conflict. For instance, very few automatic merge tools can merge two changes to the same line of code (for example, one merge changes a function name at the same line that another merge adds a comment). In this case, revision control systems resort to manual merging, performed by the user, to specify the intended merge result.

Merge algorithms

There are many different approaches to automatic merging, with subtle differences. The more notable merge algorithms include three-way merge, recursive three-way merge, fuzzy patch application, weave merge, and patch commutation.

Three-way merge

A three-way merge is performed after an automated difference analysis between a file "A" and a file "B" while also considering the origin, or common ancestor, of both files "C". It is a rough merging method, but widely applicable since it only requires one common ancestor to reconstruct the changes that are to be merged. Three way merge can be done on raw text (sequence of lines) or on structured trees. The three-way merge looks for sections which are the same in only two of the three files. In this case, there are two versions of the section, and the version which is in the common ancestor "C" is discarded, while the version that differs is preserved in the output. If "A" and "B" agree, that is what appears in the output. A section that is the same in "A" and "C" outputs the changed version in "B", and likewise a section that is the same in "B" and "C" outputs the version in "A". Sections that are different in all three files are marked as a conflict situation and left for the user to resolve. Three-way merging is implemented by the ubiquitous diff3 program, and was the central innovation that allowed the switch from file-locking based revision control systems to merge-based revision control systems. It is extensively used by the Concurrent Versions System (CVS).

Recursive three-way merge Three-way merge based revision control tools are widespread, but the technique fundamentally depends on finding a common ancestor of the versions to be merged. There are awkward cases, particularly the "criss-cross merge", where a unique last common ancestor of the modified versions does not exist.

Fortunately, in this case it can be shown that there are at most two possible candidate ancestors, and recursive three-way merge constructs a virtual ancestor by merging the non-unique ancestors first. This merge can itself suffer the same problem, so the algorithm recursively merges them. Since there is a finite number of versions in the history, the process is guaranteed to eventually terminate. This technique is used by the Git revision control tool. Git's recursive merge implementation also handles other awkward cases, like a file being modified in one version and renamed in the other, but those are extensions to its three-way merge implementation; not part of the technique for finding three versions to merge. Recursive three-way merge can only be used in situations where the tool has knowledge about the total ancestry directed acyclic graph (DAG) of the derivatives to be merged. Consequently, it cannot be used in situations where derivatives or merges do not fully specify their parent(s).

… excerpt ends here. Continue reading the full article.

Illustrations

Merge (version control): Example history graph of a version-controlled project, with merges as red arrows
Example history graph of a version-controlled project, with merges as red arrows
Merge (version control): C is the origin, A and B are derivatives of C, and D is the new output version
C is the origin, A and B are derivatives of C, and D is the new output version
Merge (version control): The "Criss-cross-merge" problem in software version control. In the left half 2 areas are being modified, X and Y. X′ and X″ are successively modified versions. The solution is shown in the right half: a virtual ancestor (the dashed circle) is created.
The "Criss-cross-merge" problem in software version control. In the left half 2 areas are being modified, X and Y. X′ and X″ are successively modified versions. The solution is shown in the right half: a virtual ancestor (the dashed circle) is created.

Worked examples

Example 1 — a first encounter with Merge (version control)

Start with the simplest possible case. Write down what Merge (version control) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Merge (version control) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Merge (version control) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Merge (version control)

In research
Merge (version control) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Merge (version control) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Merge (version control) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Configuration management, Version control, so understanding it makes those chapters shorter.
In everyday life
Look for Merge (version control) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Merge (version control)” →

How to study Merge (version control) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Merge (version control) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Merge (version control) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Merge (version control) in simple terms?

In version control, merging (also called integration) is a fundamental operation that reconciles changes made to a version-controlled collection of files. Most often, it is necessary when a file is modified on two independent branches and subsequently merged.

Why does Merge (version control) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Merge (version control)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Merge (version control).

Tags

  • Configuration management
  • Version control

Keep exploring