5

A piece of the Unison manual for force:

You can also specify -force newer (or -force older) to force Unison to choose the file with the later (earlier) modtime. In this case, the -times preference must also be enabled.

My understanding is that when conflict occurs the more recent file version is taken. But there is other option prefer and it may be set to newer as well. Unfortunately description for prefer is meager so I have no idea what prefer=newer means and what the difference is?

Mike Pierce
  • 1,390
  • 1
  • 12
  • 35
ardabro
  • 1,907
  • 16
  • 31

1 Answers1

3

Prefer Newer

Your understanding is not quite complete. When versions of a file are detected to be different, and one of those files is just an updated version of the other, Unison will copy the newer one over the other one.

Now what if you updated each version of single file on two machines without syncing in between the edits? Neither file is an updated version of the other, so it's ambiguous to Unison which one to keep. These files are said to be in conflict, and Unison will prompt you to choose a file (or if you have auto true set Unison will just skip that file). The prefer newer option will tell Unison to not be conflicted in cases like this, and just assume the file with the most recent timestamp is the one you want to have synced. This is important if you want Unison to run in the background, with options like auto true and repeat watch. Here's the relevant explanation of prefer from the manual, and note that it only matters if path or file is in conflict:

prefer xxx

Including the preference -prefer root causes Unison always to resolve conflicts in favor of root, rather than asking for guidance from the user. (The syntax of root is the same as for the root preference, plus the special values newer and older.)

This preference is overridden by the preferpartial preference.

This preference should be used only if you are sure you know what you are doing!


Force Newer

For force newer, it looks like you missed the line in the manual right before line you quoted:

Including the preference force root causes Unison to resolve all differences (even non-conflicting changes) in favor of root. This effectively changes Unison from a synchronizer into a mirroring utility.

So while the prefer option just syncs a file if there was a conflict (in particular if the file has changed), force will sync everything regardless of whether there have been changes.

Community
  • 1
  • 1
Mike Pierce
  • 1,390
  • 1
  • 12
  • 35
  • "force will sync everything regardless of whether there have been changes." If nothing changed, what is being synced? Do you have an example scenario where these options would be produce different results? – levant pied Oct 15 '19 at 16:37