简体   繁体   English

如何通过子树合并将git存储库与子模块合并到另一个子模块中?

[英]How to merge a git repository with submodules into another with subtree merge?

I have a dotfiles repository. 我有一个dotfiles存储库。 I want to merge another one with submodules ( prezto ) into it, so I can conveniently have everything in one repository without the inconvenience of submodules. 我想将另一个与子模块( prezto )合并到其中,这样我可以方便地将所有内容放在一个存储库中,而不会出现子模块的不便。

How can I subtree merge prezto into my dotfiles repository with all its submodules? 我怎样才能将prezto与其所有子模块合并到我的dotfiles存储库中?

I can use submodules, I can split and merge subtrees either the "old fashioned" way or with the newer git subtree tool. 我可以使用子模块,我可以使用“老式”方式或使用较新的git子树工具拆分和合并子树。

I just don't know how to do this specific case. 我只是不知道如何做这个具体案例。

Alexander Mikhailian created a script to convert all the submodules in subtrees, you should be able to adapt it to your case. Alexander Mikhailian创建了一个脚本来转换子树中的所有子模块,你应该能够适应你的情况。

Presenting here the steps: 在这里介绍步骤:

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

I think the easiest route for you would be to apply the script on the prezto repo and then make the repo a subtree in the dotfiles repository. 我认为最简单的方法是在prezto repo上应用脚本,然后将repo作为dotfiles存储库中的子树。

After executing the script in the prezto repository you will use the following steps to create the subtree: prezto存储库中执行脚本后,您将使用以下步骤来创建子树:

  1. Add a new remote URL pointing to the prezto repo into the dotfiles . 将指向prezto repo的新远程URL添加到dotfiles

     git remote add -f prezto user@example.com:path/prezto.git 
  2. Merge the prezto project into the local dotfiles project. prezto项目合并到本地dotfiles项目中。 This doesn't change any of your files locally, but it does prepare Git for the next step. 这不会在本地更改任何文件,但它确实为下一步准备Git。

     git merge -s ours --no-commit prezto/master 
  3. Create a new directory called prezto-subdir (or whatever you like), and copy the Git history of the prezto project into it. 创建一个名为prezto-subdir (或任何你喜欢的)的新目录,并将prezto项目的Git历史记录复制到其中。

     git read-tree --prefix=prezto-subdir/ -u prezto/master 
  4. Commit the changes to keep them safe. 提交更改以确保安全。

     git commit -m "Subtree merged in prezto" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM