gpt4 book ai didi

git - 如何提取一个 git 子目录并从中创建一个子模块?

转载 作者:IT王子 更新时间:2023-10-29 01:22:24 27 4
gpt4 key购买 nike

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

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

最佳答案

现在有一种比手动使用 git filter-branch 更简单的方法:git subtree

安装

注意 从 1.7.11 开始,git-subtree 现在是 git 的一部分(如果你安装了 contrib),所以你可能已经有了它安装了。你可以通过执行 git subtree 来检查。


从源代码安装 git-subtree(对于旧版本的 git):

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

用法

将较大的 block 分成较小的 block :

# 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

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

关于git - 如何提取一个 git 子目录并从中创建一个子模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/920165/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com