将git repo转换为子模块 [英] Convert git repo to submodule

查看:104
本文介绍了将git repo转换为子模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我对整个git主题还很陌生.但是我想做的是跨多台计算机同步我的dotfiles.我知道那里有很多教程,我掌握了基本概念.但是我的问题是更具体的问题.

So I am fairly new to the whole git topic. But what I am trying to do is syncing my dotfiles across multiple machines. I know there are plenty of tutorials out there and I got the basic concept. But my question is a tick more specific.

首先,我正在使用Windows(现在)和Vim.最重要的是,我使用vundle来管理我的插件.现在,插件本身就是git-repos.目录~/.vim(这是我要同步的主要仓库)包含它们.

First things first: I am using Windows (for now) and Vim. On top of that I use vundle to manage my plugins. Now the plugins are git-repos themselves. The directory ~/.vim (which is the main repo I want to sync) contains them.

所以我的问题是,如何初始化现有存储库的submodule?

So my question is, how do I initialize a submodule of an existing repo?

我现在得到的是~/.vim/bundle/...中的一堆绿色文件夹,它们代表另一个存储库. git status命令将它们报告为未跟踪的内容(而且不是我的.gitignore做一些时髦的事情).

What I got now is a bunch of green folders in my ~/.vim/bundle/... which represent the other repos. The git status command reports them as untracked content (and no its not my .gitignore doing some funky stuff).

如果您不熟悉绿色文件夹"现象

You might want to take a look at my repo if you are unfamiliar with the green folder "phenomenon".

P.S.其中一个子文件夹说了修改过的内容而不是未跟踪的内容,即使我没有碰过它.我不知道为什么.

P.S. One of the subfolders says modified content instead of untracked content, even though I didn't touch it. I have no idea why.

推荐答案

如果所有捆绑包都是未经修改的基本克隆,则可以执行以下操作:从dotfiles存储库的根目录:

If all of your bundles are just basic clones with no modifications, you can do something like this: From the root of your dotfiles repo:

for d in `find .vim/bundle/ -maxdepth 1 -mindepth 1 -type d`
do
    pushd $d
    export url=$(git config --get remote.origin.url)
    popd
    git submodule add $url $d
done

这应该足够好-如果任何捆绑包都不是存储库,或者如果您手动添加了它,那么它将直接越过该目录.

That should work well enough - if any bundle isn't a repository, or if you've added it manually, then it'll just pass over that directory.

然后,您可以执行git submodule foreach git pull来全部更新它们,并添加它们以更新您的dotfiles存储库引用.

Then you can then do a git submodule foreach git pull to update them all, and add them to update your dotfiles repo's references.

这篇关于将git repo转换为子模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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