Two People Changed the Same Config File? Merge Safely with diff3 — illustrative Linux troubleshooting banner

Two People Changed the Same Config File? Merge Safely with diff3

Guide context: Published 13 October 2026. The situation below is an illustrative troubleshooting scenario, not a report of an AdminHint client incident. Banner artwork is illustrative.

You have a working configuration with a local change. A colleague sends another version based on the same original. Copying either file over the other risks losing a setting. A three-way comparison helps you see what changed on each side.

The essential ingredient is the shared original file. Without it, you can compare two versions, but you cannot reliably tell which differences came from whom. This guide uses GNU diff3 on Linux and a harmless text example; it does not modify a live service.

Give the three files unambiguous names

The order that matters
Argument Example filename Meaning
First local.conf Your edited version
Second base.conf The common original
Third remote.conf The other edited version

The GNU manual defines the order as mine, older, yours. Putting the original in the wrong position changes the meaning of the merge, even if the command still runs.

Try a conflict you can understand

Create a new, empty practice directory in your home folder and enter it. The following commands write only the named practice files; do not run them in a directory containing files you need to keep.

printf 'timeout=30n' > base.conf
printf 'timeout=60n' > local.conf
printf 'timeout=45n' > remote.conf

diff3 local.conf base.conf remote.conf

Both editors changed the same setting in different ways. The computer cannot decide whether 45 or 60 seconds is the correct operational choice. That decision belongs to someone who understands the application.

Create a candidate, not a replacement

GNU diff3’s -m option produces merged output, with markers where changes conflict. Use a new output filename:

diff3 -m local.conf base.conf remote.conf > merged.candidate.conf
merge_status=$?
printf 'diff3 exit status: %sn' "$merge_status"

Capture the status immediately: running another command first replaces it. GNU diff3 reports 0 for success, 1 when conflicts are found, and 2 for trouble. In a script using automatic exit-on-error behavior, handle the conflict status explicitly rather than assuming that any nonzero result means nothing useful was produced.

Never redirect output to one of the three inputs. Shell redirection can truncate a file before diff3 reads it. Keep the original inputs unchanged so you can repeat the operation or compare your final decision.

Review every conflict block

grep -nE '^(<<<<<<<|||||||||=======|>>>>>>>)' merged.candidate.conf

Open the candidate in an editor. A marked block presents alternatives; it is not valid application configuration. Decide which value is appropriate, remove the entire marker block, and replace it with the resolved setting. In this example, record why you chose the timeout rather than silently choosing the larger number.

Repeat the marker search afterward. No matches are a useful check, but not proof that the file is valid. A clean automatic merge can still combine individually reasonable changes into a bad configuration.

Validate in the application's own language

For an actual service, use its documented syntax or configuration validator against the candidate, in a test environment where appropriate. Confirm that the command validates the candidate you intend to deploy rather than the already-active file. Different programs interpret duplicate keys, includes, and comments differently.

Only after review and validation should you back up the active configuration and follow that service's normal deployment and reload procedure. Check the specific behavior affected by the edit, then retain the inputs and the resolved candidate with a short decision note.

When to use another tool

If the files already live in Git, prefer its established review and merge workflow. If you are comparing binary files or generated content, plain-text merging may be the wrong approach. And if you have no trustworthy base, ask for it before pretending this is a three-way merge.

See GNU's diff3 option reference for supported switches. Topic inspiration: How-To Geek's diff3 introduction. The timeout example and deployment checklist are original to this guide.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *