9

我想在两台机器上同步一个包含我的 dotfiles 的 git repo 的目录。两台机器都会对 repo 中的文件进行更改。通常我使用一致来同步目录,但在这种情况下,.git即使目录内容表面上相同,目录中的文件也会有所不同。Unison 看到这一幕,举手退出。

$ unison dotfiles
changed  <-?-> changed    .git/FETCH_HEAD
changed  <-?-> changed    .git/ORIG_HEAD
changed  <-?-> changed    .git/index
changed  <-?-> changed    .git/logs/HEAD
changed  <-?-> changed    .git/logs/refs/heads/master
changed  <-?-> changed    .git/logs/refs/remotes/origin/master

此处的逐字节同步不起作用,因为即使使用相同的文件和 git 状态,内部 git 文件也可能不同。如何同步这些目录?同步后,两台机器上的所有非 git 文件和 git 状态应该相同。git state 是指提交历史和暂存,但不一定是每个内部 git 文件(例如 .gitignore、.git)的每个字节。我对 git 的了解还不够,无法更详细地说明我的意思,但如果不清楚,请发表评论。

我不想将任何 git 提交作为同步的一部分。我在这里将版本控制和同步视为两个独立的问题。

将词 git 和 sync 放入 google 会给出描述如何克隆 repo 的结果。需要明确的是,上面“同步”的使用都不是指 git 操作。

4

2 回答 2

7

Based on VonC's advise, I'm going to relax the requirement of live syncing the entire git state and simply ignore the .git directory with unison and just use git fetch.

Relevant part of my .unison/dotfiles.prf:

root = /home/khouli/dotfiles
root = ssh://other_machine//home/khouli/dotfiles
ignore = BelowPath .git

Note that BelowPath matches exactly the path .git. So depending on the project structure ignore = Name .git may be better suited. More details on pathing in Unison here.

Relevant part of my sync script:

unison dotfiles
(cd $HOME/dotfiles && git fetch)
ssh other_machine 'cd dotfiles && git fetch'

This syncs the files themselves and the commit history. It doesn't sync staging but that's not too important and it might not even be desirable. This also requires that both machines have an appropriate network connection for a git fetch. Otherwise git bundle like VonC suggests could be used.

This is just here incase anyone comes here from google and finds it useful. I'm not marking it as accepted because it'd be interesting if an answer showed up with a way to live sync a git repo.

于 2015-07-25T18:39:29.163 回答
2

此处的逐字节同步不起作用,因为即使使用相同的文件和 git 状态,内部 git 文件也可能不同。

这就是为什么您不同步 .git 文件夹的原因(其他人尝试过使用 dropbox,结果并不令人满意

我建议使用git bundle,但这个过程可能有点复杂。

还有其他用于管理和同步点文件的工具。一个非常好的方法是RichiH/vcshGitMinutes #13和这篇文中介绍。

于 2015-07-25T17:32:45.250 回答