英文:
Which workflow should I use for this nested repo situation?
问题
我正在为初学者创建一个Git教程。
我正在跟踪我的进度,例如笔记、Beamer幻灯片和练习,存储在一个Git存储库(存储库A)中。我还想创建一个示例Git存储库(存储库B),其中包含教育性的提交历史,最好将其嵌套在存储库A中。我希望能够将存储库A推送到GitHub,包括存储库B。
我已经找到了不同的方法,如子模块、子树和只将存储库B放入存储库A的.gitignore中。在我这种情况下,哪种方法是正确的选择?
英文:
I am creating a git tutorial for beginners.
I'm tracking my progress such as notes, beamer slides and exercises in a git repo (repo A). I also want to create a sample git repository (repo B) with an educational commit history and ideally nest it inside repo A. I want to be able to push repo A to github including repo B.
I have found different approaches, such as submodules, subtrees and just putting repo B into repo A's .gitignore. What's the right choice in my situation?
答案1
得分: 1
选项 A:按照说明的存储库
我建议不要尝试将 "教育性的 git 存储库" 存储为存储库。
由于您打算将其用作 "示例 git 存储库",我宁愿将其存储为一系列需要重新创建的 bash 命令,从初始的 git init my-project && cd my-project
开始。
这样,可以在设置环境的同时进行基本的 git 命令培训。文件创建可以自动化,touch README.md
或 echo "int main() {}" > main.c
,并且任何初学者可达的情况应该只需几次提交。
这种格式在此平台的问答中也很常见;示例答案:Branch off master but include changes from another unmerged branch
选项 B:简单不嵌套
由于嵌套存储库是一种高级技术,为什么不将可能复杂的培训存储库准备为一个独立的、公开可访问的存储库,只需执行一次 git clone
即可?这样,任何设置都可以简化为一条命令,大多数练习可以通过调用 git reset --hard origin/main
进行重置(尽管可能需要警告不要在培训情境之外频繁使用此命令)。
选项 C:培训轮子存储库 web 应用
有专门的 web 应用可供学习更高级的分支、合并、变基场景,而不需要首先面对真实存储库的 "困难"。其中一个受欢迎的是 Learn Git Branching。在此应用程序中,您可以针对提交树的可视化进行操作,而工作树中的任何实际工作只是通过调用 git commit
来模拟创建不透明更改。
重点是在提交和历史操作之间的逻辑关系上。这样,可以首先培训自己快速地在头脑中形象化和操作提交结构,然后再进入一个真实存储库,其中包括文件内容和合并冲突等增加的复杂性。
英文:
Option A: Repo as instructions
I would recommend against trying to store the "educational git repo" as a repository at all.
As you intend to use it as an "sample git repository", I'd rather store it as a sequence of bash commands that are needed to recreate it, starting with the initial git init my-project && cd my-project
.
That way, using the basic git commands already can be trained while setting up the environment. File creation can be automated, touch README.md
or echo "int main() {}" > main.c
, and any beginner-reachable situation should be only a few commits away.
This format is also quite common in Q&A's on this platform; example answer: Branch off master but include changes from another unmerged branch
Option B: Simply do not nest
As it is an already advanced technique to nest repos, why not prepare the possibly complex training repo as an indepdent, publically accessible repo that is only one git clone
away? That way, any setup reduces to a single command, and most exercises can be reset by one call to git reset --hard origin/main
(although one might need to warn against this command's frequent use outside of training situations..)
Option C: Training wheels repo webapp
There are dedicated webapps for learning more advanced branching, merging, rebasing scenarios without the "difficulty" of a real repository first. A popular one is https://learngitbranching.js.org/. In this application, you work against the visualization of the commit tree, and any real work in the working tree is simply simulated by calling git commit
to create an opaque change.
The focus is on the logical relationship between commits and history manipulation. That way, one can first train oneself to mentally visualize and manipulate commit structures quickly, before going into a real repository with its added complexity of file contents and merge conflicts.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论