Since I frequently use multiple devices simultaneously, I often encounter the issue of writing articles on one device and then continuing to use Logseq on another. Simply copying and pasting feels cumbersome.
I have roughly divided the solution to this problem into two stages. The first stage involves using a portable hard drive to directly copy data between different systems. During this stage, I utilized a Git bare repository.
Stage 1
git init --bare logseq-database.git
Then, in other working Git repositories, I added a remote. For example, if my disk path is E:\:
git remote add origin E:\logseq-database.git
This way, I could synchronize Logseq data directly between different devices.
Stage 2
I found using a portable hard drive still inconvenient. I repurposed a 10-year-old ThinkPad, installed Gitea on it. Initially, I used Gogs, but Gogs had unfriendly handling of submodules and inexplicable bugs. Therefore, I ultimately switched to Gitea. After setting up Gitea, I migrated the original Git repository to my local machine. For example: http://gitea.local/svtter/logseq-database.git.
Stage 3
I discovered that storing and sharing large files often caused issues. I added support for git-lfs by running:
git lfs install
and
git lfs track *.pdf
to prevent large files from leaving too much data in the .git directory.
Stage 4
Periodically back up part of the data to GitHub. However, I generally no longer do this.
When using Git for merging, one must be cautious about an issue: if a file name changes, automated merging will simply ignore it. Here’s how it typically happens: I modify a file on two devices simultaneously, and on one device, not only is the content changed, but the file name is also altered. Then, both devices perform a Git commit separately. As a result, when Git performs the merge, it won’t prompt a conflict. After Git’s automated merge, the modifications made on one of the devices will disappear.
To address this issue, the approach is to use the rebase method as much as possible during merging. However, rebasing is slow when merging files and requires a lot of manual handling.
Therefore, when modifying the same file on two devices simultaneously, first pull the remote changes. Second, avoid changing file names whenever possible. Otherwise, changes may be lost.
Fortunately, Git commit history is always preserved. If all else fails, retrieve the lost parts from the commit records and add a new commit.