obsidian-git
obsidian-git copied to clipboard
[Bug]: Data loss when mobile has conflicts
Describe the bug
First off thank you very much for this plugin. One reason I like this so much is that by using git, data can be recovered from previous commits in worst case scenarios, which is what I needed to do when I discovered this issue.
I have 2 bugs. I'll describe the general info here, with detailed reproductions steps below. In my setup, I am syncing my notes between a macbook and an iphone.
First issue. When there are merge conflicts on iOS, the instructions that are generated by the plugin explain that you can resolve the conflicts by manually reviewing and editing the text inside the conflict markers (such as those pictured below). The problem is that these conflict markers do not appear on iOS. Instead, the conflicted file appears as it did before the pull, with no way to see what was saved on the other device. Then if you commit the changes, it overwrites any changes from the other device.
<<<<<<< HEAD
this is the conflict marker example
======
This is the conflict marker example.
>>>>>>>
Second issue. When there are merge conflicts on iOS, if you "resolve" the conflicts by committing the iOS version of the files (see first issue above), then changes from multiple previous commits from the other device are reverted. This is very unexpected because it reverts changes that are unrelated to the conflicted file, or even the conflicted commit.
The repo (vault) that I used to reproduce this can be found here. The interesting thing is that note2 is missing the text "Here is a change from macbook." even though that text was commited here. The text is no longer present when iOS commits here, even though the commit shows no apparent changes.
Relevant errors (if available) from notifications or console (CTRL+SHIFT+I)
No response
Steps to reproduce
Not all of these steps may be needed but this is exactly what I did.
Initial Setup
- Macbook
- Initialize a new repo in github. Clone it to the macbook.
- Open the repo in Obsidian as a vault.
- Add 2 files through Obsidian called note1 and note2.
- Outside of obsidian, add a .gitignore file with the contents
.obsidian/ - Install Obsidian Git plugin. Set these settings:
- Merge Strategy: "Rebase"
- List filenames affected: Yes
- Add "macos" to commit messages ("vault backup macos: {{date}}")
- Add author name/email
- Using Source Control View, backup the vault
- iPhone
- Create new vault
- install Obsidian Git plugin. Set these settings:
- Enter username and personal access token
- Run the command: Obsidian Git: Clone Existing Repo
- Enter the repo url and choose the following:
- Folder: VAULT_ROOT
- Contains .obsidian? NO
- Depth of clone: empty
- Restart obsidian
- Change plugin settings:
- List filenames affected: Yes
- Add "ios" to commit messages ("vault backup ios: {{date}}")
- Add author name/email
Reproduction scenario
- On the macbook make a change to note1. Commit and push the file by pressing the "Backup" button in the Source Control View.
- On the iphone, make a change to note2, and backup through Source Control View.
- On the macbook, pull. Everything looks OK.
- macbook: change note1 again, and backup.
- ios: change note1 this time to make a merge conflict. Backup.
- Result: note1 is conflicted. However, viewing the file does not show any diff. It only shows the ios version.
- Expected Result: I expected to see the conflict markers in note1.
- ios: Backup again, which commits the ios version of the conflicted file since there was no diff info.
- macbook: Pull. The macbook changes are lost, which at this point is expected.
- macbook: Make a change to note2. Backup.
- macbook: Make a change to note1. Backup.
- ios: Make a change to note1. Backup.
- Result: note1 is conflicted. Like before, there are no diff views.
- ios: Backup again, which uses the ios version of the conflicted file.
- macbook: Pull.
- Result: Here we lose not only the macbook version of the conflicted file (note1), but we also lose the macbook changes to note2!
- Expected Result: note2 should not have been reverted.
Expected Behavior
No response
Addition context
No response
Operating system
iOS
Installation Method
None
Plugin version
2.20.5
I confirm that data lost also happens on Android.
If there is conflict, remote commit changes are "reverted"/removed/rolledbacked ( without any notice/warning or comment in commit!) And they are overrided by local changes in commit!
I don't understand why this is used: https://github.com/denolehov/obsidian-git/blob/8b6d1f328293441a5c6ca189e8f38c83ad25dd1b/src/main.ts#L998
but this seems weired. It's used 3 times in the code...
@georgeflug
I discovered this thread while facing a similar issue. Indeed, there seems to be a problem with conflict resolution on mobile, leading to data "loss." However, in my opinion, the correct approach is to prevent these conflicts. After all, the plugin serves as a backup, not a collaboration tool. If you, like me, use it to synchronize Mac/Windows with iOS and vice versa (as a single user), my suggestion is:
- Add the following to your .gitignore:
.obsidian/workspace.json
.obsidian/workspace-mobile.json
- Remove the aforementioned files from git (this is crucial, otherwise the ignore command won't be effective). For example, use:
git rm --cached .obsidian/workspace*.json
Ensure the plugin configuration is set correctly. My issue stemmed from having both "Vault Backup Interval" and "Auto Backup After Stop Editing Any File" enabled. The latter option overrode the former, leading to the following scenario:
- I edit a note on the desktop.
- Due to the "after stop editing timeout," the change isn't pushed for 5 minutes.
- I close Obsidian, and consequently, the change is never pushed.
- I open the mobile app (for example, a daily note) and edit it.
- This results in a conflict and data "loss."
My solution was to disable "Auto Backup After Stop Editing Any File" and set "Vault Backup Interval" to a specific value. It could be a decimal, for example, 0.5 for 30 seconds.
@marcinolek Thanks for the tip. I had the .gitignore set correctly, but it's possible that my plugin configuration was set in a way that contributed to conflicts.
I ended up solving this for myself in a different way. I continue to use this plugin on my desktop, but I have removed it from mobile. On mobile I set up the Working Copy app, with some iOS automations configured to automatically pull/push when opening/closing Obsidian. This solution has not given me any trouble, and I rarely get merge conflicts now.