如何 git bundle 一个完整的 repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11792671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to git bundle a complete repo
提问by Philip Oakley
I need to transfer a complete repo to a new non-networked machine, preferable as a single file entity. The git bundle allows a git fetch
, git pull
style operation in a sneakernet environment but appears to assume that you already have a working version of the repo on the destination machine.
我需要将一个完整的 repo 传输到一台新的非联网机器,最好作为单个文件实体。git bundle 允许在运动鞋网环境中进行git fetch
,git pull
风格的操作,但似乎假设您已经在目标机器上有一个工作版本的 repo。
What is the right invocation to:
什么是正确的调用:
- Bundle allthe branches in the current repo
- Start up the new repo on the destination directory, i.e. get the root commit correctly installed
- 捆绑当前 repo 中的所有分支
- 在目标目录上启动新的 repo,即正确安装根提交
I've sent a patch upstream to clarify:
我已经向上游发送了一个补丁来澄清:
`git clone` can use any bundle created without negative refspecs
(e.g., `new`, but not `old..new`).
If you want to match `git clone --mirror`, which would clone other
refs such as `refs/remotes/*`, use `--all`.
If you want to provide the same set of refs that a clone directly
from the source repository would get, use `--branches --tags` for
the `<git-rev-list-args>`.
So $ git bundle create repo.bundle --branches --tags
best matches cloning.
所以$ git bundle create repo.bundle --branches --tags
最好匹配克隆。
$ git bundle create repo.bundle --all
will provide a mirror image of your source machine, including it's remote refs.
$ git bundle create repo.bundle --all
将提供源机器的镜像,包括它的远程引用。
回答by Jakub Nar?bski
What is the right invocation to:
- Bundle all the branches in the current repo
什么是正确的调用:
- 捆绑当前 repo 中的所有分支
Simple:
简单的:
$ git bundle create repo.bundle --all
Here repo.bundle
is the name of bundle file you want to create. Note that --all
would not include remote-tracking branches... just like ordinary clone wouldn't either.
这repo.bundle
是您要创建的捆绑文件的名称。请注意,--all
不会包括远程跟踪分支......就像普通克隆也不会。
- Start up the new repo on the destination directory, i.e. get the root commit correctly installed
- 在目标目录上启动新的 repo,即正确安装根提交
First, clone
is just init
+ fetch
(+ administrativia).
首先,clone
只是init
+ fetch
(+ administrativia)。
Second, you can use bundle file everywhere the repository URL can be used, so you can simply clone
from a bundle file:
其次,您可以在任何可以使用存储库 URL 的地方使用捆绑文件,因此您可以简单地clone
从捆绑文件中获取:
$ git clone repo.bundle
This would create repo
as a git repository.
这将创建repo
为 git 存储库。
回答by thoutbeckers
First clone the repository, and include the --mirror
option.
首先克隆存储库,并包含--mirror
选项。
git clone --mirror [email protected]:path/repo.git
git clone --mirror [email protected]:path/repo.git
This ensures all remote branched are also local branches ready for bundeling.
这确保所有远程分支也是准备捆绑的本地分支。
Then run
然后运行
git bundle create repo.bundle --all
as described by the answer from Jakub Nar?bski
git bundle create repo.bundle --all
正如 Jakub Nar?bski 的回答所描述的那样
回答by patthoyts
I would suggest you tar or zip the .git folder and simply unpack it in the new location and then do git reset --hard HEAD
. Everything required for all the branches is under .git and all you should need to do is adjust any remotes in the .git/config file or remove them.
我建议您对 .git 文件夹进行 tar 或 zip 压缩,然后将其解压到新位置,然后执行git reset --hard HEAD
. 所有分支所需的一切都在 .git 下,您需要做的就是调整 .git/config 文件中的任何遥控器或删除它们。
tar cf myrepo.tgz .git
cp myrepo.tgz [USB_STICK]
... move to new machine ...
mkdir myrepo && cd myrepo
tar xpf [USB_STICK]/myrepo.tgz
git reset --hard HEAD