I have Obsidian on both my phone and PC and I use the git plugin to sync with gitlab as the origin/master. The phone is supposed to pull before pushing anything. The backups are set like that too, but I guess the phone failed to pull, but then I backed up and it overwrote the GitLab origin/master. It’s so close to being exactly what I need, but I’ve got to fix this, and figure out how to prevent that in the future.
Has anyone else had this issue? I’m also a git amateur, so could someone point me to a good link with a good explanation on how I can restore the last backup from the PC (commit). I want to be able to add and update via the phone, and I’ve been able to, but it is secondary to the computer which I’m on most days for longer periods.
Thank Everyone with Both Obsidian and the Git plugin, a truly awesome piece of software!
I don’t know if you can restore files with obsidian git plugin, but if you able to run git in terminal, you can do this:
cd <path to your obsidian folder>
It will give you the list of all commits you’ve done, from latest to first, with their names and dates. Copy the name of the commit you think is still holding your data. Now you can rewrite you files back to this state with:
git checkout <commit name>
If you are not sure exactly what commit to choose, but you remember the name and path of the file you want to restore, you can write this:
git log -1 -- <file path>
It will give you the last commit in which your file was changed (or deleted), so you should choose the one before it.
Also if you don’t want to go back completely, but just restore the specific file, you can use:
git checkout <commit name> -- <file path>
As to about how to prevent data loss in the future, I’m not sure. Git wasn’t exactly designed for automatic syncing, and conflicts happens all the time, so depending on your strategy you either stick with syncing not working at all, or something gets overwritten. Luckily you can restore everything, but I personally prefer to sync manually to be able to always watch out for error messages if they occur.
Thank You so, very much. I may try a diff or something first, if I can figure that out, there is much more on the PC side, but I don’t want to lose stuff I’d written after! But this is exactly what I wanted, a comment on how I was doing it with git and obsidian and the correction with just git. I wish there was an option to have the backup/push fail through, if the pull failed, but I’m guessing the plugin, at least one the phone side, isn’t that advanced, and you’re right, I’ll need to set that to manual instead. I’ve looked at the log, but didn’t want to go down the rabbit hole of figuring how to copy and paste from tmux or less to show that. Oh wait, I need to do a merge of my current PC and that commit right into master, right? Let me know if that’s correct or what you think