使用git子模块而不是使用gitignore在另一个repo内部进行回购有什么好处? [英] What is the advantage of using git submodules over having a repo inside another repo with a gitignore?

查看:199
本文介绍了使用git子模块而不是使用gitignore在另一个repo内部进行回购有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在研究git子模块,我们想知道如何使用子模块在另一个存储库中使用.gitignore文件创建存储库的优点(如果有的话)。



没有子模块的例子:

  mkdir a 
cd a
git init
touch test1.txt
echob> .gitignore
git add。
git commit -m添加test1.txt和gitignore

mkdir b
cd b
git init
touch test2.txt
git add。
git commit -mAdding test2.txt

git log
cd ..
git log

解决方案

当您提交时,子模块的git父级将跟踪子模块的分支和标记ID。这将确保当你签出父母(在一个已知的版本),那么子模块也将包含他们的正确的标签。



如上所述,它恰好是一个被忽略的子目录,那么基本上这些是两个独立的git repos,就好像它们不属于文件系统层次结构一样。


We've been looking into git submodules and we are wondering what advantage (if any) is there in having a repository using submodules verses having a repository within another repository with a .gitignore file.

Example without submodules:

mkdir a
cd a
git init
touch test1.txt
echo "b" > .gitignore
git add .
git commit -m "Adding test1.txt and gitignore"

mkdir b
cd b
git init
touch test2.txt
git add .
git commit -m "Adding test2.txt"

git log
cd ..
git log

解决方案

The git parent (of the submodules) will keep track of the branches and tag IDs of the submodules when you commit. That will ensure that when you check out the parent (at a known version) then the submodules will also contain their right tags.

If, as above, it just happens to be an ignored subdirectory, then basically these are two independent git repos, as if they'd not been part of a file system hierarchy.

这篇关于使用git子模块而不是使用gitignore在另一个repo内部进行回购有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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