git 如何从git存储库中删除原点

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

How to remove origin from git repository

gitgit-svn

提问by awy

Basic question: How do I disassociate a git repo from the origin from which it was cloned?

基本问题:如何将 git 存储库与克隆它的来源解除关联?

git branch -ashows:

git branch -a显示:

* master
  remotes/origin/HEAD -> origin/master

and I want to remove all knowledge of origin, and the associated revisions.

我想删除所有的起源知识,以及相关的修订。

Longer question: I want to take an existing subversion repo and make a number of smaller git repos from it. Each of the new git repos should have the full history of just the relevant branch. I can prune the repo to just the wanted subtree using:

更长的问题:我想使用现有的 subversion 存储库并从中制作一些较小的 git 存储库。每个新的 git 存储库都应该具有相关分支的完整历史记录。我可以使用以下方法将 repo 修剪为想要的子树:

git filter-branch --subdirectory-filter path/to/subtree HEAD

but the resulting repo still contains all the revisions of the now-discarded subtrees under the origin/master branch.

但是生成的 repo 仍然包含 origin/master 分支下现在丢弃的子树的所有修订。

I realise that I could use the -T flag to git-svn to clone the relevant subtree of the subversion repo in the first place. I'm not sure if that would be more efficient than later running multiple instantiations of git filter-branch --subdirectory-filteron copies of the git repo but, in any case, I would still like to break the link with the origin.

我意识到我可以首先使用 git-svn 的 -T 标志来克隆 subversion 存储库的相关子树。我不确定这是否比稍后git filter-branch --subdirectory-filter在 git repo 的副本上运行多个实例更有效,但无论如何,我仍然想断开与原点的链接。

回答by Amber

Fairly straightforward:

非常坦率的:

git remote rm origin


As for the filter-branchquestion - just add --prune-emptyto your filter branch command and it'll remove any revision that doesn't actually contain any changes in your resulting repo:

至于filter-branch问题 - 只需添加--prune-empty到您的过滤器分支命令,它就会删除任何实际上不包含在生成的存储库中的任何更改的修订:

git filter-branch --prune-empty --subdirectory-filter path/to/subtree HEAD

回答by Mandeep Singh Gill

Remove existing origin and add new origin to your project directory

删除现有源并将新源添加到您的项目目录

>$ git remote show origin

>$ git remote rm origin

>$ git add .

>$ git commit -m "First commit"

>$ git remote add origin Copied_origin_url

>$ git remote show origin

>$ git push origin master