- Here is a step-by-step how-to article tailored for Logseq users who want to restore their SQLite database (db.sqlite) from a previous Git commit. This is applicable to Logseq Desktop version.
- If you use Logseq with Git version control, you can restore your
db.sqlite
file to a previous state by using Git commands. This is useful if something goes wrong, or you want to revert to an earlier version of your knowledge graph. -
Prerequisites
- You have Git installed on your system.
- You are comfortable using the command line.
- Your Logseq graph is tracked in a Git repository and the
db.sqlite
file is committed to Git. - (Optional but recommended) You have sqldiff installed to compare database versions.
- Step 1: Open Your Logseq backup Repository Folder
- Step 2: View Commit History for db.sqlite
- Step 3: Identify the Commit to Restore
- Step 4: Restore the db.sqlite File
- Step 5: (Optional) Commit the Restored Version
- If you want to keep this restored version as the new current version and share it with collaborators, commit the change:
-
git add db.sqlite git commit -m "Restore db.sqlite from commit <commit-hash>"
- Step 6: (Optional) Compare Two Versions
-
If you want to compare two versions before restoring, you can extract them and use
sqldiff
:```shell git show <older-commit-hash>:db.sqlite > old.db.sqlite git show <newer-commit-hash>:db.sqlite > new.db.sqlite sqldiff old.db.sqlite new.db.sqlite ```
- This will show you the differences between the two database files.
-
-
Troubleshooting
- File not found: Make sure you are in the correct repository and that
db.sqlite
is tracked by Git. - Accidentally overwritten: You can always repeat the above process with a different commit hash.
- File not found: Make sure you are in the correct repository and that
-
Summary
- Use
git log
to find the commit you want. - Use
git checkout <commit-hash> -- db.sqlite
to restore that version. - Optionally, commit the restoration.
- Use
sqldiff
to compare database versions if needed. - By following these steps, you can safely restore your Logseq SQLite database to any previous version tracked in your Git repository.
- Use
2 Likes