我可以使用Git子模块将一个分支的副本保留在同一存储库中另一个分支的目录中吗? [英] Can I use Git submodules to keep a copy of one branch inside a directory of another branch in the same repository?

查看:73
本文介绍了我可以使用Git子模块将一个分支的副本保留在同一存储库中另一个分支的目录中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Web开发教程.在其中,学生从一个名为"chapter-1-start"的git分支开始,当她完成该教程章节中的步骤时,她的代码应与"chapter-1-complete"中的代码基本相同.我想在"lib/reference_app"之类的目录中的"chapter-1-start"分支中包含"chapter-1-complete",以便她可以比较或在必要时剪切并粘贴从complete到开始的文件.这是我的目标:

I'm writing a web development tutorial. In it, a student starts in a git branch called 'chapter-1-start' and when she finishes the steps in that tutorial chapter, her code should look substantially the same as the code in 'chapter-1-complete.' I'd like to include 'chapter-1-complete' inside a the 'chapter-1-start' branch in a directory like 'lib/reference_app' so she can compare or, if necessary, cut and paste files from complete to start. Here are my goals:

  1. 将所有代码保存在一个存储库中.
  2. 'chapter-1-start'内的引用分支'chapter-1-complete'应该是最新的-不必更新.

我认为这对于子模块是可行的,但是对它们没有经验.我担心通过放置递归引用会丢失整个git历史.

I think this is possible with submodules, but have no experience with them. I'm wary of losing my entire git history by putting in a recursive reference.

推荐答案

为特定分支的子模块添加相同的仓库是我过去做过的一个技巧:请参阅"

Adding the same repo as a submodule for a particular branch is a trick I have done in the past: see "Copying Doxygen Documentation from gh-pages branch into a subfolder of Master branch" as an example.

在您的情况下,学生可以按照自己的回购协议进行以下操作:

In your case, the student can, in his/her own repo, do:

git branch chapter-1-complete origin/chapter-1-complete
git checkout chapter-1-start
git submodule add -b chapter-1-complete -- /remote/url/of/your/own/repo
git commit -m "ADd chapter-1-complete branch as submodule"
git push

然后在chapter-1-start中完成的简单git submodule update --remote就足以更新chapter-1-complete子文件夹(子模块的根目录)的内容.请参阅" git子模块跟随分支".

Then a simple git submodule update --remote done in chapter-1-start will be enough to update the content of the chapter-1-complete subfolder (root directory of the submodule). See "git submodule follows branch".

这篇关于我可以使用Git子模块将一个分支的副本保留在同一存储库中另一个分支的目录中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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