你忽略.gitignore中的git子模块还是将它提交给你的repo? [英] Do you ignore a git submodule in your .gitignore or commit it to your repo?

查看:200
本文介绍了你忽略.gitignore中的git子模块还是将它提交给你的repo?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我每次运行 git status 时,现在在 project_dir / vendor / submodule_one 中为我的项目添加了一个子模块>我得到修改:vendor / submodule_one(新提交)



我的问题是最好的处理方式有了这个?我的主项目不需要了解 vendor / submodule_one -folder到我的 .gitignore 我的子模块的具体细节?



或者当我更改并提交更改到我的子模块时,是否还需要在我的主项目中进行提交?



刚开始使用子模块,似乎无法找到更多信息。 解决方案

不,您不需要将子模块添加到 .gitignore 中:父项从子模块中将看到 gitlink 特殊条目,模式160000 )。



这意味着:直接在子模块中进行的任何更改都需要在父目录中进行提交。

这样,父目录将记录正确提交子模块的状态:该提交是上面提到的gitlink;

你可以在 git submodule update(true nature的子模块)


子模块的主要思想是基于组件的方法,您可以在其中参考特定提交中的其他回购。但是,如果您在这些子模块中更改了任何内容,则还需要更新父回购中的这些引用。






请注意,使用Git 2.13(Q2 2017),而 not 忽略gitlink,您仍然可以忽略子模块:

  git config submodule。< name> .active false 

=https://stackoverflow.com/a/43440263/6309>忽略git submodule的新提交。






注意:使用Git 2.15.x / 2.16(Q1 2018),忽略子模块会更精确。 c $ c>并没有停留在嵌入在被忽略的目录中的单独项目的工作树上,而是在该项目中列出了文件,而不是将目录本身显示为忽略。



请参见提交fadb482 (2017年10月25日) Johannes Schindelin( dscho

(由 Junio C Hamano - gitster - in commit da7996a ,2017年11月6日)


status :不要被排除的子目录中的子模块混淆



我们精心地将 exclude 标志传递给 treat_directory()函数,以便我们可以表明递归时排除了文件而不是未跟踪。



但我们还没有以相同的方式处理子模块。



因此, git status --ignored --untracked 带有子模块
子模块在gitignored tracked / 中会显示$ b中的子模块$ b 未追踪文件 部分,例如



 关于分支主
未被跟踪的文件:
(使用git add< file> ...来包含将被提交的内容)

tracked / submodule /

被忽略的文件:
(使用git add -f< file> ...来包含将要提交的内容)

tracked / submodule / initial.t




相反,我们希望它能在 忽略文件
区段中显示子模块:




 关于分支主
被忽略的文件:
(使用git add -f< file> ...包括在将要提交的内容中)

跟踪/子模块/


I've added a submodule to my project in project_dir/vendor/submodule_one now each time I run git status I get modified: vendor/submodule_one (new commits).

My question is whats the best way to deal with this? Do I add the vendor/submodule_one-folder to my .gitignore as my main project shouldn't need to know about the specifics of my submodule?

Or when I'm changing and commiting changes to my submodule do I need to make commits in my main project also?

Just getting started with submodules and couldn't seem to find much info beyond setting them up.

解决方案

No, you don't need to add your submodule to your .gitignore: what the parent will see from your submodule is a gitlink (a special entry, mode 160000).

That means: any change directly made in a submodule needs to be followed by a commit in the parent directory.
That way, the parent directory will record the right commit for the state of the submodule: That commit is the "gitlink" mentioned above;

You can read more about that policy in "git submodule update (true nature of submodules)".
The main idea behind submodules is a component-based approach, where you reference other repos at specific commits. But if you change anything in those submodules, you need to update those references in the parent repo as well.


Note that with Git 2.13 (Q2 2017), while not ignoring the gitlink, you can still ignore the submodule with:

git config submodule.<name>.active false

See more at "Ignore new commits for git submodule".


Note: with Git 2.15.x/2.16 (Q1 2018), ignoring a submodule is more precise.
"git status --ignored -u" did not stop at a working tree of a separate project that is embedded in an ignored directory and listed files in that other project, instead of just showing the directory itself as ignored.

See commit fadb482 (25 Oct 2017) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit da7996a, 06 Nov 2017)

status: do not get confused by submodules in excluded directories

We meticulously pass the exclude flag to the treat_directory() function so that we can indicate that files in it are excluded rather than untracked when recursing.

But we did not yet treat submodules the same way.

Because of that, git status --ignored --untracked with a submodule submodule in a gitignored tracked/ would show the submodule in the "Untracked files" section, e.g.

On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    tracked/submodule/

Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    tracked/submodule/initial.t

Instead, we would want it to show the submodule in the "Ignored files" section:

On branch master
Ignored files:
  (use "git add -f <file>..." to include in what will be committed)

    tracked/submodule/

这篇关于你忽略.gitignore中的git子模块还是将它提交给你的repo?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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