同步包含git存储库的目录 [英] Sync directories containing git repository with unison

查看:113
本文介绍了同步包含git存储库的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两台机器上同步一个包含我的dotfiles的git仓库的目录。这两台机器都会更改回购中的文件。通常,我使用unison来同步目录,但在这种情况下,即使目录内容表面上相同, .git 目录中的文件也会出现分歧。

  $ unison dotfiles 
已更改< - ? - > ;改变.git / FETCH_HEAD
已更改< - ? - >更改.git / ORIG_HEAD
已更改< - ? - >更改.git / index
已更改< - ? - >更改.git / logs / HEAD
已更改< - ? - >更改.git / logs / refs / heads / master
已更改< - ? - >更改.git / logs / refs / remotes / origin / master

此处逐字节同步不起作用,因为即使使用相同的文件和git状态,内部git文件也可能不同。我怎样才能同步这些目录?同步后,两台机器上的所有非git文件和git状态都应该相同。通过git状态我的意思是提交历史和分期,但不一定每个内部git文件的每个字节(例如.gitignore,.git)。我对git的了解不够详细,但是如果这还不清楚,只是发表评论。

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



将git和sync这两个词放到google中会给出描述如何克隆回购的结果。要清楚的是,上面的sync的用法都没有涉及到git动作。

基于VonC的建议,我将放宽实时同步整个git状态的要求,并简单地忽略 .git 目录并使用 git fetch code>。



我的 .unison / dotfiles.prf 的相关部分:

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

我的同步脚本的相关部分:

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

这会同步文件本身和提交历史记录。它不会同步分段,但这并不太重要,甚至可能不需要。这也要求两台机器都有适合 git fetch 的网络连接。否则 git bundle 就可以使用VonC的建议。



这里仅仅是来自google和发现的任何人它很有用。我并不认为它是被接受的,因为如果答案显示出来的方式是同步一个git repo,它会很有趣。


I want to sync a directory containing a git repo of my dotfiles on two machines. Both machines will make changes to the files in the repo. Normally I use unison for syncing directories but in this case the files in the .git directory diverge even when the directory contents are ostensibly the same. Unison throws up its hands and quits when it sees this.

$ 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

A byte-by-byte sync here doesn't work because even with the same files and git state the internal git files may be different. How can I sync these directories? After the sync, all non-git files and the git state should be identical on the two machines. By git state I mean commit histories and staging but not necessarily every byte of every internal git file (e.g. .gitignore, .git). I don't know enough about git to go into more detail on what I mean by that but if that's unclear just comment.

I don't want to make any git commits as part of syncing. I see version control and synchronization as two separate issues here.

Putting the words git and sync into google gives results describing how to clone a repo. Just to be clear, none of the uses of "sync" above are referring to git actions.

解决方案

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

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.

这篇关于同步包含git存储库的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆