【问题标题】:How to remove origin from git repository如何从 git 存储库中删除源
【发布时间】:2012-03-02 17:50:53
【问题描述】:

基本问题:如何将 git repo 与其克隆的来源解除关联?

git branch -a 显示:

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

我想删除所有原始知识以及相关的修订。

更长的问题:我想利用现有的颠覆回购并从中制作一些较小的 git 回购。每个新的 git 存储库都应该只包含相关分支的完整历史记录。我可以使用以下命令将 repo 修剪为所需的子树:

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

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

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

【问题讨论】:

    标签: git git-svn


    【解决方案1】:

    相当简单:

    git remote rm origin
    

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

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

    【讨论】:

    • 嗯。获取error: Could not remove config section 'remote.origin'
    【解决方案2】:

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

    >$ 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
    

    【讨论】:

      【解决方案3】:

      感谢 mandeep 提供的 git remote show origin 命令。

      在我的情况下 git branch -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>
      

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

      (我的)案子解决了! =D

      再见, 斯凯巴克。

      【讨论】:

        猜你喜欢
        • 2017-08-15
        • 2011-01-04
        • 2011-09-12
        • 2011-09-21
        • 2010-09-11
        相关资源
        最近更新 更多