Conflicts
Predicting conflicts before an operation
9 min read
Finding a conflict only after starting the operation means stopping halfway, with the operation in progress bar and files with markers. Versora tries to warn you beforehand: it simulates the operation in memory, without touching the working directory, the stage or the branches, and says in which files it will conflict. You decide whether to go ahead, prepare the ground first or give up.
This is the main page about conflict prediction. It explains:
- the prediction between branches: the badge on the branches that would conflict with the target, the warning before a merge or rebase and the note in the merge request form;
- the preview before cherry-pick and revert;
- and, at the end, the app's other predictions, with the link to where each one is explained.
The predictions on this page use the same technique: git merge-tree, which calculates the result
of a combination without a working directory. The objects the simulation would create go into a
temporary object database, not into your repository. No file, branch or stage changes.
These apply to all of them:
- It compares commits. Uncommitted changes in the working directory aren't taken into account.
- It never blocks the operation. If the simulation before a merge, rebase, cherry-pick or revert fails or takes longer than 15 seconds, the operation goes ahead as usual, without a warning.
- It needs a recent git: 2.38 for the prediction between branches and 2.40 for the cherry-pick and revert preview. With an older git, the prediction is unavailable and the operation goes ahead directly. See Git version.
The prediction between branches simulates merging one branch into another. It appears in three places: the badge on branches, the warning before a merge or rebase and the note in the merge request form. All three are in Preferences › Checks › Conflict prediction, because they're part of the app's checks.
- Left panel, LOCAL section: the conflict icon next to the branch that is expected to conflict.
- Graph: the same icon, smaller, on the local branch label.
- Palette (Ctrl+P): "Refresh conflict prediction" (detail: "Compares local branches with the target").
Hover over the icon to see the explanation and the list of files: "Conflict predicted: merging feature/login into main is expected to conflict in 2 files:" followed by the files.
- The prediction compares each local branch with the prediction target (below).
- It runs on its own when you switch tabs or when the local or remote branches change (commit, fetch, checkout…), after a short pause, so several changes in a row become a single calculation.
- The result for each pair of commits is saved: after a fetch, only the branches that actually moved are recalculated.
- Up to 200 branches are calculated at a time.
- A badge only applies to the tip it was calculated on: if the branch got new commits, the badge disappears until the next calculation.
In Preferences › Checks › In this repository › Prediction target ("The branch the others are compared with. Empty = automatic: develop with Gitflow, otherwise the remote's default branch."):
- empty (automatic): Gitflow's
develop, if it's initialized; otherwise, the remote's default branch (origin/HEAD, ormain, ormaster); - a name: the branch the others are compared with.
The field shows what is in effect, for example "automatic (origin/main)".
"Refresh conflict prediction" calculates it right away and says the result:
- "Conflict predicted with origin/main: feature/login (2), feature/relatorio (1)";
- "No local branch is expected to conflict with origin/main.";
- with the prediction turned off, the command is unavailable ("prediction is turned off in Preferences").
When you merge or rebase from a branch's menu, when you drag a branch onto another and in a local squash merge: while it calculates, the bar shows "Predicting conflicts…". If the simulation predicts a conflict, the Before merging (or Before rebasing) dialog opens with the Conflict predicted block. With no conflict predicted, the operation goes ahead directly, without a dialog.
- Start the merge or the rebase normally.
- If there's a predicted conflict, read the Conflict predicted block:
- "Merging feature/login into main is expected to conflict in 2 files:" and the list (up to 40; the rest becomes "… and 12 more");
- "If you continue, the merge stops at the conflicts and the conflict editor helps you resolve them." (or, in the rebase, "If you continue, the rebase stops at each commit that conflicts.");
- "The prediction only considers the commits in main and feature/login; uncommitted changes aren't taken into account."
- Choose Merge anyway (or Rebase anyway) to go ahead, or Back to cancel.
In the Create merge request (or Create pull request) form, the app simulates merging the source branch into the chosen target. If there's a conflict, the note "This merge request is expected to conflict with origin/main in 2 files: src/login.ts, src/api/auth.ts. Update the branch with the target first, or resolve it on the server." appears (with more than five files, the first five and "and N more"). The note changes when you switch the target. See Create a merge request.
In Preferences › Checks, Conflict prediction group:
| Option | What it does | Default |
|---|---|---|
| In the background › Predict conflicts | Compares each local branch with the target and marks the ones that would conflict, in the panel and in the graph. | On |
| Before merging or rebasing › Warn when it would conflict | The dialog before merge and rebase ("From the menu or by dragging one branch onto another."). | On |
| When creating a merge/pull request › Warn in the form | "Shows the files expected to conflict with the target in the form." | On |
| In this repository › Prediction target | The branch the others are compared with. | Automatic |
| In this repository › Checks enabled here › Conflict prediction | Turns all of this off only in this repository ("Turning one off here only affects this repository."). | On |
A git merge-tree --write-tree between the two commits, with the temporary object database:
git merge-tree --write-tree main feature/login
The exit code says whether the combination was clean; with a conflict, the output carries the files.
There's nothing to undo: the prediction only reads. If you go ahead and the merge or rebase stops at a conflict, Abort on the bar puts everything back as it was. See Operations stopped halfway.
- "Conflict prediction needs git 2.38 or newer (installed: 2.30.1). Update Git for Windows to turn it on.": with an old git, the prediction is unavailable. See Git version.
- "The configured target "develop" doesn't exist in this repository.": the prediction target points to a branch that doesn't exist. Fix it or leave it blank.
- "There's no default branch to compare with (no origin/HEAD, main or master).": in automatic mode, the app didn't find the default branch. Enter the target.
- "The histories have no common ancestor.": the two branches have no commit in common; there's no way to predict.
- "Prediction isn't available in this repository.": the prediction doesn't apply (for example, without a target).
The options are in Preferences › Checks (table above). The company can hide or lock that page through the company policy; see Company policy.
- Conflict prediction in the checks
- Merge, squash merge and rebase between branches
- Dragging branches
- Create a merge request
The preview runs on its own, before the operation, when you use:
- Commit menu: Cherry-pick this commit and Revert commit.
- Selection of several commits in the graph (Ctrl+click or Shift+click) › menu: Cherry-pick 3 commits and Revert 3 commits.
While the simulation runs, the indicator shows "Predicting conflicts…".
- Choose the cherry-pick or the revert normally.
- If the simulation doesn't find a conflict, the operation goes ahead directly, without any question.
- If it does, the The cherry-pick will conflict (or The revert will conflict) dialog appears, with the commit and the list of files. For example: "Cherry-picking a1b2c3d ("Corrige o cálculo do frete") will conflict in 2 files:", followed by "• src/frete.ts" and "• src/pedido.ts". With more than eight files, the list ends in "• and 5 more".
- With several commits, the dialog says which one conflicts: "commit 2 of 3, b4c5d6e ("…")". The simulation applies the commits in the order the operation will apply them and stops at the first one that would conflict.
- Choose:
- Cherry-pick anyway (or Revert anyway): the operation starts and stops at the conflict, as usual. "If you go ahead, the operation stops at the conflict and you resolve it in the conflict editor (Abort puts everything back)."
- Cancel: nothing happens.
| Option | What it does | Default |
|---|---|---|
| Preferences › Operations › Cherry-pick and revert › Predict conflicts before cherry-pick and revert | Turns the preview on or off. When it's off, cherry-pick and revert start directly. | On |
For each commit, in order, the app combines the commit's diff (from its parent to it; in a revert, the reverse) with the accumulated result starting from HEAD:
git merge-tree --write-tree --name-only --no-messages -z --merge-base=<parent> <HEAD> <commit>
The objects the simulation creates go into a temporary object database, not into the repository. The exit code says whether the combination was clean or conflicted, and in that case the output carries the files. Nothing changes in the working directory, the stage or the branches.
The preview doesn't change anything, so there's nothing to undo. If you go ahead and the operation stops at a conflict, Abort on the bar puts everything back as it was. If you resolve the conflicts and finish the operation (Continue), the cherry-pick or revert goes into Ctrl+Z as a whole, like one that didn't stop. See Operations stopped halfway and Undo and redo.
- The preview needs git 2.40 or newer. With an older git, it doesn't run and the operation goes ahead directly; the git version bar lists "the cherry-pick and revert conflict preview (2.40)" among the unavailable features (see Git version).
- Like every prediction, it only helps: if it fails or takes longer than 15 seconds, the operation goes ahead as usual, without a warning.
- Uncommitted changes aren't taken into account: a cherry-pick can still be refused by git if it would overwrite a file you changed.
- The preview applies to the menu items above. Other ways of cherry-picking, such as dragging a commit onto a branch, have their own checks (see Dragging branches and commits).
- Preferences › Operations › Cherry-pick and revert: "Simulates the operation in memory first (git merge-tree) and warns you if it will conflict, saying in which files. Needs git 2.40 or newer."
- The company can hide or lock the Operations page of Preferences (id
ergoOps) through thepreferences.hiddenorpreferences.lockedpolicy. See Company policy.
Versora uses the same technique (simulating in memory with git merge-tree) in other places. Each
one is explained on its own page:
| Where | What it warns about | Page |
|---|---|---|
| Local squash merge | The conflict prediction before the squash | Squash |
| Bulk rebase of outdated branches | The exact conflict of each branch, leaving out the ones that would conflict | Hygiene and workflow |
| Dragging a commit onto another | Rebase with preview and plan | Dragging branches and commits |
| Applying a patch and applying part of a stash | Whether it applies directly, only with 3-way or doesn't apply | Patches and Stash |