从分支创建新项目 [英] Creating a new project out of a branch
问题描述
前段时间,我们从Git的主分支中创建了一个分支.目前,该分支机构之间的分歧很大,以至于无法将其合并到主分支中,因此我们考虑使用该分支创建一个新项目.
Some time ago we made a branch from our master branch in Git. Currently, this branch has diverged so much that it makes no sense merging it into the master and we consider creating a new project out of it.
是否有Git功能可以使我们从该分支中创建一个新的独立项目,并保留所有历史记录?
Is there any Git functionality that would allow us creating a new independent project out of this branch, keeping all the history?
推荐答案
您可以使用:
git clone --branch A --single-branch B C
--branch
告诉Git使用分支A
作为新存储库中的当前分支(而不是原始存储库的master
分支).
--branch
tells Git to use branch A
as the current branch in the new repo (instead of the master
branch of the original repo).
--single-branch
告诉它仅将当前分支(使用--branch
设置在此处)可访问的提交复制到克隆中.
--single-branch
tells it to copy into the clone only the commits that are reachable from the current branch (set here using --branch
).
B
是原始存储库(本地目录或URL),C
是用于创建克隆的本地目录.
B
is the original repository (a local directory or an URL), C
is the local directory where to create the clone.
在新仓库中,Git将原始仓库(B
)设置为origin
远程服务器.如果您不需要此链接,则可以随时将其删除:只需在新存储库中运行git remote remove origin
.
In the new repo, Git sets the original repo (B
) as the origin
remote. If you don't need this link you can remove it any time: just run git remote remove origin
in the new repo.
这篇关于从分支创建新项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!