使用子回购 (vim) 推送本地 git 回购

Push local git repo with sub repos (vim)

我使用 Vim 和 pathogen 作为插件管理器,并且我已经将很多插件克隆到我的 .vim 文件夹中。现在我希望我的自定义 vim 可以在多个系统上轻松访问,所以我将我的 .vim 目录设为 git 存储库。我用 'git add .' 添加了所有内容并将其推送到 bitbucket 存储库。现在每当我想将这个 repo 克隆到另一台计算机时,它只会创建插件应该所在的文件夹,而不是文件。我猜它们是自动添加为子模块的,但我似乎无法使用像 'git submodule update' 这样的简单命令将它们从各自的来源中拉出来,它只说“在 .gitmodules 中找不到路径的子模块映射'bundle/plugin'。 我需要做什么来防止这种情况发生? 提前致谢。

是的,您可以使用子模块将 .vim 的内容存储为 Git 存储库,但我可以建议一种不同的方法。

使用一个简单的脚本将您的插件克隆到 pathogen 期望的适当位置可能更容易管理所有这些。

我也在多台计算机之间穿梭,这种方法对我很有帮助。

这是我使用的(Perl 脚本):

#!/usr/bin/perl -w   
use strict;

my $dotVimDir;
my $home=$ENV{HOME};
my @repos=qw(
    https://github.com/tpope/vim-fugitive|tpope-fugitive
    https://github.com/tpope/vim-flagship|tpope-flagship
    # etc...
);

sub runCommand($) {
    my ($command)=@_;
    open CMD,"$command |";
    my @output=<CMD>;
    close CMD;
    return @output;
}

MAIN: {
    my $platform=$^O;
    if($platform eq 'linux') {
        $dotVimDir="$home/.vim";
    } elsif($platform eq 'MSWin32') {
        $dotVimDir="$home/vimfiles";
    } else {
        print "unknown platform\n";
        exit 1;
    }

    runCommand("cp -R ./vimplugins/autoload $dotVimDir");
    runCommand("cp -R ./vimplugins/ftplugin $dotVimDir");

    my ($repo,$folderName);
    foreach(@repos) {
        ($repo,$folderName)=split("\Q|",$_,2);

        my $fullPath="$dotVimDir/bundle/$folderName";
        if (-d "$fullPath") {
            runCommand("git -C $fullPath stash -u");
            runCommand("git -C $fullPath pull origin master");
        } else {
            runCommand("git clone $repo $fullPath");
        }
    }

    exit;
}

您可以将此脚本保存在一个单独的存储库中(可能称为 myconfig 之类的东西)。我还在这个 repo 中保留了其他备用文件(例如各种 autoloadftplugins)并且这个脚本也复制了这些文件。

Here is a ruby script 也实现了这个目标。

你的 .vim 是你自己的,所以你可以告诉它你从哪里得到的提交。由于您已经拥有克隆,最简单的方法就是直接进行配置。默认值保存在 .gitmodules 文件中,

git config -f .gitmodules submodule.fugitive.path fugitive
git config -f .gitmodules submodule.fugitive.url https://github.com/tpope/vim-fugitive.git

等等。熟悉 shell 函数,使小型生产运行得心应手:

make-github-submodule () {
        git config -f .gitmodules submodule..path 
        git config -f .gitmodules submodule..url https://github.com/.git
}

make-github-submodule fugitive tpope/vim-fugitive
make-github-submodule vundle VundleVim/Vundle.vim

等等,看起来很方便。