Git将嵌套的git repos视为常规文件/文件夹 [英] Git treat nested git repos as regular file/folders

查看:79
本文介绍了Git将嵌套的git repos视为常规文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样组织的顶级git repo:

I have a top level git repo organized like so:

  • .git/
  • repoA/
    • .git/
    • 文件
    • file2
    • 文件夹/
    • ...

    我怎样才能像git一样将git添加到 add commit repoA (和 repoA/.git )它们是常规文件/文件夹吗?

    How can I get git to add and commit repoA (and repoA/.git) as if they were regular files/folders?

    特别是,我想绕过将文件夹视为子模块的处理,但我想保留嵌套存储库的分支/历史记录(因此需要 .git 文件夹).

    Specifically, I want to bypass the treatment of such a folder as a submodule but I want to retain the branches/history of the nested repo (so the .git folder is required).

    我不想更改嵌套仓库的状态(通过提交或合并历史记录),也不想将其推送到远程服务器上的单独仓库中.

    I do not want to alter the state of the nested repo (by committing or merging histories) and do not want to push it to a separate repo on the remote.

    预期的结果与我稍后对 tar repoA 并取消对 tar 的使用相同.也就是说,所有文件都完整无缺,没有经过git修改或特殊处理.

    The intended result is the same as if I were to tar repoA and un-tar it later. That is, all the files are intact with no modification or special treatment by git.

    推荐答案

    您可以查看

    You can look into git subtree.

    为此,如果您当前有子模块,则可以遵循"将git存储库从子模块转换为子树":

    For that, if you currently have submodules, you can follow "Convert a git repository from submodules to subtrees":

    cat .gitmodules |while read i
    do
      if [[ $i == \[submodule* ]]; then
        mpath=$(echo $i | cut -d\" -f2)
        read i; read i;
        murl=$(echo $i|cut -d\  -f3)
        mcommit=`eval "git submodule status ${mpath} |cut -d\  -f2"`
        mname=$(basename $mpath)
        echo -e "$name\t$mpath\t$murl\t$mcommit"
        git submodule deinit $mpath
        git rm -r --cached $mpath
        rm -rf $mpath
        git remote add $mname $murl
        git fetch $mname
        git branch _$mname $mcommit
        git read-tree --prefix=$mpath/ -u _$mname
    fi
    done
    git rm .gitmodules
    

    (首先在您的存储库的副本上对其进行测试)

    (test it on a copy of your repo first)

    另请参阅"何时使用git子树?",与 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆