如果 Syncthing 同步的文件同时也在 git 仓库下时,会出现这种问题,设备 A 通过 git 上传到 GitHub ,并通过 syncthing 同步到设备 B 。但设备 B 也有相同的 git 仓库,就会出现下面的问题。

```
krdw@thinkpad:~/blog$ git status
On branch main
Your branch is behind 'origin/main' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/content/blog/build-your-rss-flow.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/content/blog/building-homeserfer-with-laptop-v2.md
        src/content/blog/file-sync-syncthing-tailscale.md

no changes added to commit (use "git add" and/or "git commit -a")
```

此时 build-your-rss-flow 的修改和 file-sync-syncthing-tailscale 的新增都已经被设备 A 提交修改到 GitHub 上,building-homeserfer-with-laptop-v2 的新增两台设备都没有进行提交。

请教一下各位大佬,在设备 B 我该如何操作呢?以保证和设备 A 相同,git 仓库同步为最新,且未提交更改的文件继续保留,因为设备 B 一删设备 A 也同步会被删。
举报· 49 次点击
登录 注册 站外分享
1 条回复  
msg7086 小成 2024-7-8 12:22:20
你同步的时候包括了.git 吗?如果包括了的话,三台机器的当前状态应该是完全相同的。
如果不包括.git ,那就只有 working directory 里的文件是相同的,另外几台机器需要手动 git fetch 再 git reset HEAD 应该就行了。
返回顶部