4

I have 2 laptops with one plaintext file, which has to be synced - it is used as a database for a 3rd party software. Customer wants to sync the content of that file on a daily manner.

First idea was to make a script which would upload file to Dropbox, but in case of confilct (both users remove line A and first user add line B instead, second user add line C instead) Dropbox creates a separate file. EDIT: was going to mention, but forgot to say: in case of conflict, both lines B and C should replace line A - "take both" strategy.

Second idea is to put file to repository, sounds easy, but i'm not sure how to setup auto resolving, because i don't want merge tool GUI to appear during the process.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64
  • are you allowed to override customer's modifications? – Jossef Harush Kadouri Feb 15 '16 at 18:01
  • What would you want it to do in the case of conflicts? Use both lines B and C, choose one randomly, or something else? – David Deutsch Feb 15 '16 at 18:01
  • @DavidDeutsch Thanks for reminding - somehow i forgot to add that to the question. Edited. Both B and C should be used instead of A, order is not important. – Vitalii Vasylenko Feb 16 '16 at 11:59
  • @JossefHarush Hi, which modifications? Customer has no idea about Git or Dropbox - well, maybe he has, but doesn't care - that's why i want to put everything into a script and run it from time to time - and that's why i want to avoid any extra GUIs so he would not be frightened. – Vitalii Vasylenko Feb 16 '16 at 12:00

2 Answers2

4

You have the git rerere command for your help.

This is exactly for this command is for.

git rerere

Recorded Reused Resolution

# enabled the option to record the 
git config --global rerere.enabled true

By the way, if you prefer rerere to auto-stage files it solved (I do), you can ask it to: you just need to tweak your configuration like so:

git config --global rerere.autoupdate true

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
1

If you want all conflicts resolved with changes from both sides being included, add the following to your .gitattributes file:

* merge=union

This will make git do what you want.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54
  • Regarding the documentation the file should be located in `$GIT_DIR/info/attributes` but this folder only contains a file named "exclude". So do you have to create file `.gitattributes` first? – Chilly Code Aug 27 '21 at 21:29