如何将 Git 分支移出到其自己的存储库中?

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

How do I move a Git branch out into its own repository?

gitbranchextract

提问by Aupajo

I have a branch that I'd like to move into a separate Git repository, and ideally keep that branch's history in the process. So far I've been looking at git filter-branch, but I can't make out whether it can do what I want to do.

我有一个分支,我想将它移到一个单独的 Git 存储库中,并且最好在此过程中保留该分支的历史记录。到目前为止,我一直在研究git filter-branch,但我无法确定它是否可以做我想做的事情。

How do I extract a Git branch out into its own repository?

如何将 Git 分支提取到其自己的存储库中?

回答by CB Bailey

You can simply push a branch to a new repository. All of its history will go with it. You can then choose whether to delete the branch from the original repository.

您可以简单地将分支推送到新存储库。它的所有历史都会随之而来。然后您可以选择是否从原始存储库中删除该分支。

e.g.

例如

git push url://to/new/repository.git branch-to-move:new-branch-name

For a new repository, new-branch-name is typically master.

对于新存储库,new-branch-name 通常是 master。

Creating a new, empty repository can be done with git init.

可以使用git init.

回答by Damon

This will keep the history of all the branches, but make your copy point to the one branch in particular:

这将保留所有分支的历史记录,但让您的副本特别指向一个分支:

git clone -b newbranch CurrentRepo NewRepo

This does not 'move' anything, just makes a copy.

这不会“移动”任何东西,只是制作一个副本。