我在不同的 PC 上有两个 git 存储库。我在他们每个人身上都有一些本地的分支机构。我不想将此分支发送到远程服务器,只是将它们保留在本地。那么如何在不使用网络的情况下进行同步呢?我可以只在一台 PC 上压缩存储库并移动到另一台吗?那安全吗?也许我可以以某种方式从每个分支导出最新的更改?
最佳答案
与其制作一个裸克隆,我更喜欢制作一个 bundle (参见“How can I email someone a git repository?”),生成一个文件,更容易复制(例如在 USB 内存棒上)
好处是它确实具有裸存储库的一些特征:您可以从中提取或克隆它,但您只需担心一个文件。
machineB$ git clone /home/me/tmp/file.bundle R2
This will define a remote called "
origin
" in the resulting repository that lets you fetch and pull from the bundle. The$GIT_DIR/config
file inR2
will have an entry like this:
[remote "origin"]
url = /home/me/tmp/file.bundle
fetch = refs/heads/*:refs/remotes/origin/*
To update the resulting mine.git repository, you can fetch or pull after replacing the bundle stored at
/home/me/tmp/file.bundle
with incremental updates.
After working some more in the original repository, you can create an incremental bundle to update the other repository:
machineA$ cd R1
machineA$ git bundle create file.bundle lastR2bundle..master
machineA$ git tag -f lastR2bundle master
You then transfer the bundle to the other machine to replace
/home/me/tmp/file.bundle
, and pull from it.
machineB$ cd R2
machineB$ git pull
关于git - 如何同步两个git仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4860166/