使用版本历史导出 git

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11879287/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 07:18:46  来源:igfitidea点击:

Export git with version history

git

提问by codejammer

I need to export a git repository content and import it in a target repository. I know of two alternatives to do it, but they do not solve my problem

我需要导出 git 存储库内容并将其导入目标存储库。我知道有两种替代方法,但它们不能解决我的问题

a) Add the source repository as a remote and do a merge to the target. I cannot use this as both repositories are not on the same network

a) 将源存储库添加为远程存储库并合并到目标存储库。我不能使用它,因为两个存储库不在同一个网络上

b) Use git archive and copy the contents to the target. In this git archive the revision info is lost.

b) 使用 git archive 并将内容复制到目标。在这个 git 档案中,修订信息丢失了。

I need something that does an archive along with the version history and enables me to merge in the target. How can this be done?

我需要一些可以与版本历史记录一起存档的东西,并使我能够在目标中进行合并。如何才能做到这一点?

回答by antak

git bundleis provided for this exact purpose.

git bundle正是为此目的而提供的。

Example:

例子:

  1. Bundle your source repository in its entirety

    git bundle create my_repo.bundle --all

  2. Take ``my_repo.bundle'' to where your target is

  3. From your target, load up your source commit objects

    git bundle unbundle my_repo.bundle

    ...from which point you can merge/rebase/cherry-pick your desired source commits into your target repository to your heart's content.

    Otherwise, pulling works just the same:

    git pull my_repo.bundle

  1. 完整捆绑您的源存储库

    git bundle create my_repo.bundle --all

  2. 将“my_repo.bundle”带到目标所在的位置

  3. 从你的目标,加载你的源提交对象

    git bundle unbundle my_repo.bundle

    ...从这一点上,您可以将所需的源提交合并/rebase/cherry-pick 到您的目标存储库中,以满足您的需求。

    否则,拉动的工作原理是一样的:

    git pull my_repo.bundle

Compared to cloning, bundles are easier to transfer because they're smaller as your files aren't carried in their checked out state.

与克隆相比,捆绑包更容易传输,因为它们更小,因为您的文件不是在签出状态下携带的。

Other reasons for using bundle:

使用 bundle 的其他原因:

  • Unlike using clone --bare(which doesn't checkout your files), bundles are created and packed as a single file so you don't need additional compressing/tarballing.

  • You could also simply tarball your source repository (or just the .git directory), but you'll be carrying over all the excess cache and garbage that builds up under .git/.

  • 与 using clone --bare(它不检查您的文件)不同,bundle 是作为单个文件创建和打包的,因此您不需要额外的压缩/tarball。

  • 你也可以简单地压缩你的源存储库(或只是 .git 目录),但你将携带在 .git/ 下建立的所有多余的缓存和垃圾。

回答by Hiery Nomus

Git clone the repository onto a USB stick, laptop, or some other data transfer medium. Hook that up to the other machine, add add the medium as a remote and pull/merge the changes from there...

Git 将存储库克隆到 U 盘、笔记本电脑或其他一些数据传输介质上。将其连接到另一台机器上,将媒体添加为远程并从那里拉/合并更改...

Any clone from the repository actually contains all the history, so the question is really how can you get a clone to the other machine.

存储库中的任何克隆实际上都包含所有历史记录,因此问题实际上是如何将克隆复制到另一台机器上。

Also see: this question

另见:这个问题

回答by darnir

You want to create a fork of your current repository it would seem. Let me know if I got this right: You wish to clone a particular git repository. Work on the clone and then merge the changes into the original repository?

您想为当前存储库创建一个分支,看起来是这样。如果我做对了,请告诉我:您希望克隆一个特定的 git 存储库。处理克隆然后将更改合并到原始存储库中?

This is done my creating a fork of your repository and then pulling the changes from the original source for commit changes.

这是完成我创建存储库的分支,然后从原始源中提取更改以进行提交更改。

回答by dunni

You can just zip the complete repository folder, then copy it to the destination workstation (via usb stick, etc.), and add that local repository as remote repository. Then you can fetch and merge.

您可以压缩完整的存储库文件夹,然后将其复制到目标工作站(通过 U 盘等),并将该本地存储库添加为远程存储库。然后你可以获取和合并。