14

What if machine A and machine B shares have a directory previously in sync via rsync, and A changes a file and B changes the same file, and you rsync from A to B?

Is it perhaps anything like a merge conflict in git?

Can the conflict be easily resolved?

25

Rsync doesn't try to resolve conflicts. This isn't its job. Rsync doesn't even have a way to detect that both sides have modified the file, because it has no information about any common ancestor.

With the default options, the source file is unconditionally copied to the destination, overwriting the destination file. With the option -u, the source file is copied only if the destination file is missing or older than the source file. With the option --ignore-existing, the source file is only copied if the destination file doesn't exist.

If you want to detect conflicts, you need a tool that's aware of when the files were last synchronized, so that it can distinguish {destination = old version, source = new version} from {destination = new version 1, source = new version 2}. Use Unison, which does precisely that. Unison is a bidirectional synchronizer: it copies the file that's been modified since the last synchronization to the side where the file hasn't been modified. If neither side has been modified, or if both sides have been modified identically, it does nothing. If both sides have been modified in different ways, it tells you and lets you choose to skip, copy in one direction or copy in the other direction.

If you want automatic conflict resolution, i.e. automatic merges (when possible — there are always cases where a manual merge is necessary), use a revision control system such as git.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.