git 备份和设置2台电脑之间同步
我是 git 新手。需要一些建议才能知道我的设置是否正确。请阅读以下内容:
我在我的开发计算机上使用 git 进行 2 个独立的项目,并希望将所有内容备份到 USB 驱动器上(设置为 git bare 存储库)。此外,我想在另一台计算机上同步这些项目(用于部署)。
Computer1 上的 2 个项目路径如下:
/machine1/path/proj1
/machine1/path/proj2
这就是我的设置方式(对 proj2 重复完全相同的步骤)
#Initialize git repo
cd /machine1/path/proj1
git init
git add .
git commit -a -m "proj 1 first commit"
#Backup on USB
cd /usb/backup
mkdir proj1.git
cd proj1.git
git init --bare
cd /machine1/path/proj1
git push --mirror /usb/backup/proj1.git
#Clone to other computer
cd /machine2/path
git clone /usb/backup/proj1.git
#After making changes on machine1, I update machine2 using this command
git pull /usb/backup/proj1.git
问题:
- 这些步骤对于 (i) 设置、(ii) 在 USB 上备份、(iii) 同步到其他计算机是否正确?或者有正确/更好的方法来做到这一点?
- 我错误地执行了这些命令
cd /machine2/path/proj2
git pull /usb/backup/proj1.git
我期望 git 显示一条错误消息...类似“尝试将 proj2 与 proj1 存储库同步”之类的内容,但它在 proj1 内创建了 proj2 的子目录。我的设置有缺点吗?我预计这样的操作需要 --force
开关,否则会产生致命错误
I'm new to git. Need some advise to know if my setup is correct. Please read below :
I'm using git for 2 separate projects on my development computer and want to backup everything on a USB drive (setup as a git bare repo). Additionally, I want to sync these projects on another computer (for deployment).
The 2 projects paths on computer1 are
/machine1/path/proj1
/machine1/path/proj2
This is how I've setup (repeated exact same steps for proj2)
#Initialize git repo
cd /machine1/path/proj1
git init
git add .
git commit -a -m "proj 1 first commit"
#Backup on USB
cd /usb/backup
mkdir proj1.git
cd proj1.git
git init --bare
cd /machine1/path/proj1
git push --mirror /usb/backup/proj1.git
#Clone to other computer
cd /machine2/path
git clone /usb/backup/proj1.git
#After making changes on machine1, I update machine2 using this command
git pull /usb/backup/proj1.git
Question:
- Are these steps correct for (i) setup, (ii) backup on USB, (iii) sync to other machines? Or is there a right/better way to do it ?
- I mistakenly executed these commands
cd /machine2/path/proj2
git pull /usb/backup/proj1.git
I expected git to show an error message ... something like "trying to sync proj2 with proj1 repo" but instead it created a subdirectory of proj2 inside proj1. Is there a shortcoming in my setup ? I expected an action like this would require a --force
switch or else produce a fatal error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些步骤基本上是正确的,但我更喜欢 使用 git bundle 和 USB 密钥(即我更喜欢在 USB 密钥上每个项目一个 文件,而不是许多文件:机会较少文件损坏)。您可以创建一个带有标签和分支,然后拉取从那些捆绑包中。
关于拉取问题,我建议设置远程:
这样,您就可以“
pull origin
”,而不是手动输入地址(您可能会混淆)。有关更多信息,请参阅 Groking git 远程使用。
The steps are essentially correct, except I prefer using git bundle with an USB key (i.e. I prefer having on an USB key one file per project, instead of many files: less chances of file corruption). You can create one with tags and branches, and then pull from those bundles.
Regarding the pull issue, I would recommend setting a remote:
That way, you would "
pull origin
" instead of manually entering an address (that you can mix up).See Groking git remote usage for more.
您还可以通过简单地为 USB 设置远程以及生产服务器的远程来使用接收后挂钩方法。 post-receive 钩子会强制检查到您指定的位置,因此当您需要时,您只需键入“git push usb”,它就会检查 -f 到您的 USB 记忆棒或生产服务器。
一探究竟...
http://toroid.org/ams/git-website-howto
You could also use a post-receive hook method by simply setting up a remote for your USB, as well as a remote for your production server. The post-receive hook forces a checkout to where ever you tell it to, so when you need to you could just type "git push usb" and it should checkout -f to your USB stick, or production server.
Check it out...
http://toroid.org/ams/git-website-howto