如何从 git 存储库中删除 origin

发布于 2025-01-04 06:03:17 字数 578 浏览 1 评论 0原文

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

git Branch -a 显示:

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

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

更长的问题:我想采用现有的 subversion 存储库并从中创建一些较小的 git 存储库。每个新的 git 存储库都应该具有相关分支的完整历史记录。我可以使用以下命令将存储库修剪为所需的子树:

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

但生成的存储库仍然包含 origin/master 分支下现已废弃的子树的所有修订。

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

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

git branch -a shows:

* 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:

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.

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-filter on copies of the git repo but, in any case, I would still like to break the link with the origin.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

临走之时 2025-01-11 06:03:17

相当简单:

git remote rm origin

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

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

Fairly straightforward:

git remote rm origin

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

git filter-branch --prune-empty --subdirectory-filter path/to/subtree HEAD
贵在坚持 2025-01-11 06:03:17

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

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

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
大姐,你呐 2025-01-11 06:03:17

在我的情况下 gitbranch -r 将继续在本地存储库上显示 origin/master (在我在远程和本地上重命名 master 之后)

这修复了它:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote prune origin
Pruning origin
URL: https://github.com/SkybuckFlying/PascalCoin
 * [pruned] origin/master

E:\SourceCode\PascalCoinGit\PascalCoin>

命令:(

git remote show origin

之前见过但完全忘记了)

结果:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote show origin
* remote origin
  Fetch URL: https://github.com/SkybuckFlying/PascalCoin
  Push  URL: https://github.com/SkybuckFlying/PascalCoin
  HEAD branch: PascalCoinMaster
  Remote branches:
    GUIExperimentalBugFixes1       tracked
    GUIExperimentalBugFixes2       tracked
    GUIExperimentalBugFixes3       tracked
    GUIExperimentalBugFixes4       tracked
    GUIExperimentalBugFixes5       tracked
    MergeTest                      tracked
    PIP-0026Windows7Implementation tracked
    PascalCoinMaster               tracked
    SkybuckMaster                  tracked
    TestPascalCoinMaster           tracked
    refs/remotes/origin/master     stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    GUIExperimentalBugFixes1       merges with remote GUIExperimentalBugFixes1
    GUIExperimentalBugFixes2       merges with remote GUIExperimentalBugFixes2
    GUIExperimentalBugFixes4       merges with remote GUIExperimentalBugFixes4
    GUIExperimentalBugFixes5       merges with remote GUIExperimentalBugFixes5
    MergeTest                      merges with remote MergeTest
    PIP-0026Windows7Implementation merges with remote PIP-0026Windows7Implementation
    SkybuckMaster                  merges with remote SkybuckMaster
  Local refs configured for 'git push':
    GUIExperimentalBugFixes1       pushes to GUIExperimentalBugFixes1       (up to date)
    GUIExperimentalBugFixes2       pushes to GUIExperimentalBugFixes2       (up to date)
    GUIExperimentalBugFixes3       pushes to GUIExperimentalBugFixes3       (up to date)
    GUIExperimentalBugFixes4       pushes to GUIExperimentalBugFixes4       (up to date)
    GUIExperimentalBugFixes5       pushes to GUIExperimentalBugFixes5       (up to date)
    MergeTest                      pushes to MergeTest                      (up to date)
    PIP-0026Windows7Implementation pushes to PIP-0026Windows7Implementation (fast-forwardable)
    PascalCoinMaster               pushes to PascalCoinMaster               (up to date)
    SkybuckMaster                  pushes to SkybuckMaster                  (up to date)
    TestPascalCoinMaster           pushes to TestPascalCoinMaster           (up to date)

E:\SourceCode\PascalCoinGit\PascalCoin>

是的,gitbranch - r 现在显示它已经消失了!

In my case git branch -r would keep showing origin/master on the local repository (after I renamed master on remote and local)

This fixed it:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote prune origin
Pruning origin
URL: https://github.com/SkybuckFlying/PascalCoin
 * [pruned] origin/master

E:\SourceCode\PascalCoinGit\PascalCoin>

Command:

git remote show origin

(Seen it before but completely forgot about it)

Result:

E:\SourceCode\PascalCoinGit\PascalCoin>git remote show origin
* remote origin
  Fetch URL: https://github.com/SkybuckFlying/PascalCoin
  Push  URL: https://github.com/SkybuckFlying/PascalCoin
  HEAD branch: PascalCoinMaster
  Remote branches:
    GUIExperimentalBugFixes1       tracked
    GUIExperimentalBugFixes2       tracked
    GUIExperimentalBugFixes3       tracked
    GUIExperimentalBugFixes4       tracked
    GUIExperimentalBugFixes5       tracked
    MergeTest                      tracked
    PIP-0026Windows7Implementation tracked
    PascalCoinMaster               tracked
    SkybuckMaster                  tracked
    TestPascalCoinMaster           tracked
    refs/remotes/origin/master     stale (use 'git remote prune' to remove)
  Local branches configured for 'git pull':
    GUIExperimentalBugFixes1       merges with remote GUIExperimentalBugFixes1
    GUIExperimentalBugFixes2       merges with remote GUIExperimentalBugFixes2
    GUIExperimentalBugFixes4       merges with remote GUIExperimentalBugFixes4
    GUIExperimentalBugFixes5       merges with remote GUIExperimentalBugFixes5
    MergeTest                      merges with remote MergeTest
    PIP-0026Windows7Implementation merges with remote PIP-0026Windows7Implementation
    SkybuckMaster                  merges with remote SkybuckMaster
  Local refs configured for 'git push':
    GUIExperimentalBugFixes1       pushes to GUIExperimentalBugFixes1       (up to date)
    GUIExperimentalBugFixes2       pushes to GUIExperimentalBugFixes2       (up to date)
    GUIExperimentalBugFixes3       pushes to GUIExperimentalBugFixes3       (up to date)
    GUIExperimentalBugFixes4       pushes to GUIExperimentalBugFixes4       (up to date)
    GUIExperimentalBugFixes5       pushes to GUIExperimentalBugFixes5       (up to date)
    MergeTest                      pushes to MergeTest                      (up to date)
    PIP-0026Windows7Implementation pushes to PIP-0026Windows7Implementation (fast-forwardable)
    PascalCoinMaster               pushes to PascalCoinMaster               (up to date)
    SkybuckMaster                  pushes to SkybuckMaster                  (up to date)
    TestPascalCoinMaster           pushes to TestPascalCoinMaster           (up to date)

E:\SourceCode\PascalCoinGit\PascalCoin>

Yup, git branch -r now shows it's gone!

陌路黄昏 2025-01-11 06:03:17

使用这个> git 显示来源 > git 远程 rm 原点

Use this> git show origin > git remote rm origin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文