【问题标题】:moving a repo to a new branch/repo将 repo 移动到新的分支/repo
【发布时间】:2020-08-23 00:45:33
【问题描述】:

我刚刚将我正在构建的一个 php 项目推送到名为 php 的远程仓库,然后我意识到我需要将它放在该仓库的子目录中。我对 git 有点陌生,我不知道如何获取本地仓库并将其推送到远程仓库中的子目录。谁能告诉我我需要做什么?我是合并它、移动它还是什么?

【问题讨论】:

    标签: git command-line


    【解决方案1】:

    将现有 git 项目添加到另一个现有 git 存储库的最佳方法是将其添加为子模块。

    git submodule add [URL to Git repo] 
    git submodule init 
    

    通过运行 git submodule init 后跟 git submodule update 来初始化存储库的子模块。

    切换到子模块的目录并检查您添加的项目的所需分支,例如,git checkout master

    【讨论】:

      【解决方案2】:

      您可以使用git filter-branchlike so 重写您的回购历史:

      git filter-branch --tree-filter 'mkdir -p /path/to/tmp; mv * /path/to/tmp; mkdir subdir; mv /path/to/tmp/* subdir/' --tag-name-filter cat --prune-empty -- --all
      

      git filter-repo

      git filter-repo --path-rename /:subdir/
      

      然后push -f 你重写的master 分支。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-30
        • 2014-02-16
        • 2021-09-19
        • 2011-05-26
        • 2021-12-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多