GNU TeXmacsUser manualReferenceAboutEnglish
Resolving conflicts

When two versions of a document are merged, for instance when you get the changes of a coauthor, Git combines the changes made on both sides since their common ancestor. For ordinary text files, Git works line by line: two different changes of the same line produce a conflict, and conflict markers are written into the file. For TeXmacs documents, where a whole paragraph is often stored on a single line, this would produce many useless conflicts, and the markers would break the document.

TeXmacs therefore merges its documents structurally: paragraphs, words, markup (such as sections or emphasized text) and mathematical formulas are compared separately. Every change which was made on only one side is applied automatically, even when both authors changed the same paragraph. For instance, if the original text is “The quick brown fox jumps”, if you wrote “The slow brown fox jumps” and your coauthor wrote “The quick brown fox leaps”, then the result is “The slow brown fox leaps”. Only when the same words were changed in two different ways a real conflict remains.

By default, Git first merges the files line by line, as usual, and marks the documents in which both sides changed the same paragraph as having a conflict; the structured merge is then done when you resolve the conflict, as explained below. With Version\(\rightarrow\)Git\(\rightarrow\)Merge documents structurally, Git directly uses the structured merge of TeXmacs, so that only the documents with real conflicts remain to be resolved (see the end of this page).

Resolving the conflicts of a document

When getting the changes of your coauthors leaves conflicts, TeXmacs opens the status page, which lists the files with conflicts; after Version\(\rightarrow\)Git\(\rightarrow\)Merge branch, the dialog which reports the conflicts offers to show this page. The conflicts are also shown at the top of the Git panel. For a TeXmacs document with a conflict, the Version menu starts with the entries:

Resolve conflict

Merge the document structurally, and show the remaining conflicts in the document. For each of them, your version is displayed as the old version (in red) and the version of your coauthor as the new version (in green). The footer tells how many conflicts remain; if there are none, then the document was merged automatically, and you only have to check the result. The document must not have unsaved edits: save or revert it first. The bar at the bottom of the window shows the number of conflicts; its buttons Previous and Next go from one conflict to the other, the buttons Mine and Theirs after Keep retain one of the two versions, and those after Show choose which versions are displayed; the same commands are in the menus Version\(\rightarrow\)Retain (Keep my version and Keep their version) and Version\(\rightarrow\)Differences\(\rightarrow\)Show. You may of course also edit the text of the conflict directly.

Changes which are clearly independent are merged, also in neighbouring paragraphs: for instance a paragraph removed by you and the next one changed by your coauthor, or a paragraph edited by you and a new one added next to it by your coauthor. When TeXmacs cannot be sure of what belongs to what, it prefers a conflict to a wrong merge. This happens for changes in neighbouring words of a paragraph, for a paragraph changed on both sides into texts without enough words in common, or for almost the same paragraph added by both of you.

Besides the text, the style packages and the settings of the document (Document menu) are merged as well: a package or a setting added, changed or removed on one side only is taken over. When the same setting or the main style was changed differently on both sides, your version is kept (during a rebase, the version of your coauthors, see below), and this counts as a conflict, which the message at the bottom of the window names. The packages added by your coauthor come after yours, in the order of their document.

Mark as resolved

Save the document and tell Git that its conflicts are resolved. If some differences were not processed yet, then you are warned first.

Once all files are resolved, commit the result with Version\(\rightarrow\)Commit: the dialog proposes the message prepared by Git for the merge. When you were synchronizing, synchronize again to send the merge to your coauthors.

Other files, such as images or bibliographies, are not merged by TeXmacs: edit them with the appropriate program, then use Version\(\rightarrow\)Mark as resolved or the corresponding button of the status page. If a document was deleted on one side and changed on the other, then you have to decide by hand whether to keep it. If a document was created on both sides independently, then both versions are compared instead of being merged.

During a rebase (see working with coauthors), the roles are reversed: Git considers the commits of your coauthors as the base, so that your version is displayed as the new one (in green); Mine and Keep my version still retain your version. For the settings and the main style changed on both sides, however, the version of your coauthors is kept, and the message says so.

Merging from the command line

If you or your coauthors also use Git in a terminal or in another program, then Version\(\rightarrow\)Git\(\rightarrow\)Merge documents structurally asks Git to call TeXmacs for merging the TeXmacs documents of the repository. It records in the file .gitattributes that files with the extension .tm should be merged by TeXmacs, and it configures your copy of the repository accordingly. The conflicts which remain are then written into the documents as differences which TeXmacs can display, instead of text markers. This needs a repository in which TeXmacs may run Git (see Version\(\rightarrow\)Use Git in this folder); otherwise nothing is configured, and the message says why. If the structured merge fails, then the usual text merge of Git is used instead.

The file .gitattributes can be committed, but each coauthor who wants to benefit from structured merges outside TeXmacs has to use this command once in their own copy. For the others, Git keeps merging line by line.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".