如何提取一个git子目录并从中创建一个子模块? [英] Howto extract a git subdirectory and make a submodule out of it?

查看:378
本文介绍了如何提取一个git子目录并从中创建一个子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前我开始了一个项目,并将所有内容存储在一个主目录中。
在我的主目录Project中有几个包含不同内容的子目录:
Project / paper包含用LaTeX编写的文档
Project / sourcecode / RailsApp包含我的rails应用程序。

Project已被GIT化,并且在paper和RailsApp目录中都有很多提交。现在,因为我想为我的RailsApp使用cruisecontrol.rb,所以我想知道是否有一种方法可以在不丢失历史的情况下从RailsApp中创建子模块。



任何建议?

现在有一个更简单的方法来做到这一点,而不是手动使用git filter-branch: hit =http://github.com/apenwarr/git-subtree =noreferrer> git subtree

安装



  git clone https://github.com/apenwarr/git-subtree.git 

cd git-subtree
sudo rsync -a ./git-subtree.sh / usr / local / bin / git-subtree

或者如果你想要手册页和所有的

  make doc 
make install



用法



将大块拆分为更小的块:

 #进入项目根目录
cd〜/ my-project

#创建一个只包含为'foo'
g的孩子承诺它的子树分裂 - 前缀= foo --branch = foo-only

#从项目中删除'foo'
git rm -rf ./foo

#为'foo'创建一个git仓库(假设我们已经在github上创建了它)
mkdir foo
pushd foo
git init
git remote add origin git@github.com: my-user / new-project.git
git pull ../ foo-only
git push origin -u master
popd

#将'foo'添加为git submodule to`my-project`
git submodule add git@github.com:my-user / new-project.git foo

有关详细文档(手册页),请阅读 git-subtree.txt


I started a project some months ago and stored everything within a main directory. In my main directory "Project" there are several subdirectories containing different things: Project/paper contains a document written in LaTeX Project/sourcecode/RailsApp contains my rails app.

"Project" is GITified and there have been a lot of commits in both "paper" and "RailsApp" directory. Now, as I'd like to use cruisecontrol.rb for my "RailsApp" I wonder if there is a way to make a submodule out of "RailsApp" without losing the history.

Any suggestions?

解决方案

Nowadays there's a much easier way to do it than manually using git filter-branch: git subtree

Installation

git clone https://github.com/apenwarr/git-subtree.git

cd git-subtree
sudo rsync -a ./git-subtree.sh /usr/local/bin/git-subtree

Or if you want the man pages and all

make doc
make install

Usage

Split a larger into smaller chunks:

# Go into the project root
cd ~/my-project

# Create a branch which only contains commits for the children of 'foo'
git subtree split --prefix=foo --branch=foo-only

# Remove 'foo' from the project
git rm -rf ./foo

# Create a git repo for 'foo' (assuming we already created it on github)
mkdir foo
pushd foo
git init
git remote add origin git@github.com:my-user/new-project.git
git pull ../ foo-only
git push origin -u master
popd

# Add 'foo' as a git submodule to `my-project`
git submodule add git@github.com:my-user/new-project.git foo

For detailed documentation (man page), please read git-subtree.txt.

这篇关于如何提取一个git子目录并从中创建一个子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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