书接上回。 用 git submodule(子模块)同步多个 obsidian 库的配置文件 - 经验分享 - Obsidian 中文论坛
使用 git submodule
之后,放弃了很多 .obsidian
里当前库的数据文件,这样对于用 git 在多设备间备份整库的时候会导致缺少一些数据。所以想到了用符号链接的方式将数据文件存放到 .obsidian
外面(其实也可以将插件等存放到外面),然后在 .obsidian
中链接数据文件。
- 在库目录下创建
.obsidian_link
文件夹。 - 将
.gitignore
中添加的这些文件移动到.obsidian_link
文件夹中。然后移除.gitignore
中的这些内容。(理论上插件的数据文件可以这样操作。)
core-plugins.json
graph.json
workspace
workspaces.json
daily-notes.json
templates.json
- 使用管理员打开
powershell
,进入.obsidian
文件夹。使用New-Item -ItemType SymbolicLink -Path {{文件名}} -Target ..\.obsidian_link\{{文件名}}
在.obsidian
中创建符号链接。
New-Item -ItemType SymbolicLink -Path core-plugins.json -Target ..\.obsidian_link\core-plugins.json
New-Item -ItemType SymbolicLink -Path graph.json -Target ..\.obsidian_link\graph.json
New-Item -ItemType SymbolicLink -Path workspace -Target ..\.obsidian_link\workspace
New-Item -ItemType SymbolicLink -Path workspaces.json -Target ..\.obsidian_link\workspaces.json
New-Item -ItemType SymbolicLink -Path daily-notes.json -Target ..\.obsidian_link\daily-notes.json
New-Item -ItemType SymbolicLink -Path templates.json -Target ..\.obsidian_link\templates.json
插件 data.json
的符号链接方式:
New-Item -Path .obsidian_link\plugins\obsidian-spaced-repetition\ -ItemType Directory # 新建插件文件夹
New-Item -ItemType SymbolicLink
-Path .obsidian\plugins\obsidian-spaced-repetition\data.json -Target ..\..\..\.obsidian_link\plugins\obsidian-spaced-repetition\data.json # 创建相对链接
注意相对链接的路径 ..\..\..\
。
- 先执行 submodule 的
git commit
,然后执行库的git commit
。 - 在另外的地方 clone 仓库,注意
git
命令需要加上-c core.symlinks=true
,同时 windows 需要在管理员权限下执行。比如:
git clone -c core.symlinks=true ...
git -c core.symlinks=true submodule init
git -c core.symlinks=true submodule update --remote -f
core.symlinks=true
能否写入 git config
有待确认。
注意:此方法和 OneDrive 同步有冲突!