Git:我可以禁止在状态、差异等中列出“修改的内容”/脏子模块条目吗?
有时(我认为是在 1.6.x 版本左右)git 意识到子模块内部的变化。这只会让我恼火:
$ git status vendor | grep modified: # modified: vendor/rails (modified content)
$ git diff vendor/ diff --git a/vendor/rails b/vendor/rails --- a/vendor/rails +++ b/vendor/rails @@ -1 +1 @@ -Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f +Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f-dirty
请让它停止?
编辑:
好的,我有答案了。现在我还有一个问题:
我可以把它放在 ~/.gitconfig
中吗?从我最初的情况来看,我似乎不能,并且通过浏览补丁我没有看到任何有希望的东西。 (我想我仍然可以创建别名。)
Somewhen (around the 1.6.x releases, I think) git became aware of changes inside submodules. That only serves to annoy me:
$ git status vendor | grep modified: # modified: vendor/rails (modified content)
$ git diff vendor/ diff --git a/vendor/rails b/vendor/rails --- a/vendor/rails +++ b/vendor/rails @@ -1 +1 @@ -Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f +Subproject commit 046c900df27994d454b7f906caa0e4226bb42b6f-dirty
Please make it stop?
Edit:
Ok, so I have an answer. Now I have another question:
Can I put this in ~/.gitconfig
? From my initial it appears that I cannot, and I didn't see anything promising by skimming the patch. (I guess I can still make an alias.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
甚至可以为 .gitmodules 文件中每个添加的子模块设置忽略模式。
就在今天,我遇到了这个问题,并在找到解决方案后立即在我的博客中写了一篇文章: 如何忽略 git 子模块中的更改
它的要点:
只需在该 .gitmodules 文件中添加一行即可:
There is even a possibility to set the ignore mode for every added submodule within the .gitmodules file.
Just today I encountered this problem and immediately wrote an article in my blog about it after finding a solution: How to ignore changes in git submodules
The gist of it:
Just add one line to that
.gitmodules
file:您可以抑制两种更改通知。
第一个是
未跟踪内容
,当您对子模块进行更改但尚未提交这些更改时,就会发生这种情况。父存储库会注意到这些,并且git status
相应地报告它:modified:modules/media (untracked content)
您可以使用以下命令抑制这些内容:
但是,一旦您提交了这些更改,父存储库将再次注意到并相应地报告它们:
如果您也想抑制这些更改,则需要忽略
所有
更改There are two kinds of change notices you can suppress.
The first is
untracked content
which happens when you make changes to your submodule but have not yet committed those. The parent repository notices these andgit status
reports it accordingly:modified: modules/media (untracked content)
You can suppress these with :
However, once you commit those changes, the parent repository will once again take notice and report them accordingly:
If you want to suppress these too, you need to ignore
all
changes更新:请参阅(并投票)nilshaldenwang 的 回答关于向
.gitmodules
文件添加一个配置参数以忽略给定子模块的脏状态的可能性。因此 git 1.7.2 已发布,并包含用于
status
的--ignore-submodules
选项。来自
git help status
:我想要的值是
dirty
。我使用别名是因为我很懒:
Update: See (and upvote) nilshaldenwang's answer regarding the possibility to add to the
.gitmodules
file a config parameter for ignoring dirty state of a given submodule.So git 1.7.2 is out and includes the
--ignore-submodules
option forstatus
.From
git help status
:The value that I want is
dirty
.I use an alias because I'm lazy:
正如您所提到的,补丁 git 子模块:忽略摘要和状态的脏子模块 是在制作中。
Git 1.7.2-rc2 版本中还宣布:
含义:
将此视为一种选择并不完全是目前选择的方法:
“
git diff
”和“git status
”将为每个子模块使用该配置值。使用“
--ignore-submodule
”会覆盖此默认值(并且将在其中添加新参数“none”以能够覆盖配置设置)。Git 2.13(2017 年第 2 季度)提供了另一种使 git status(或任何 git 命令)忽略特定子模块的方法:
请参阅“忽略 git 子模块的新提交”。
As you mention, the patch git submodule: ignore dirty submodules for summary and status is in the making.
Also announced in the Git 1.7.2-rc2 release:
Meaning:
Regarding this as an option is not exactly the approach chosen for now:
"
git diff
" and "git status
" will use that config value for each submodule.Using "
--ignore-submodule
" overrides this default (and the new parameter "none" will be added there to able to override the config settings).Another approach to make git status (or any git command) to ignore a particular submodule is available with Git 2.13 (Q2 2017):
See more at "Ignore new commits for git submodule".
您还可以
在
.git/config
文件中设置submodule.ignore = dirty
。--global
将在您的~/.gitconfig
中设置忽略标志并应用于您的所有存储库。如果没有它,它应该在.git/config
中为您当前所在的存储库进行设置。我能找到的唯一文档是 git-config 文档。我将它从 .gitmodules 文件移到我的 ~/.gitconfig 中,它仍然对我有用。
You can also use
to set
submodule.ignore = dirty
in your.git/config
file.--global
will set the ignore flag in your~/.gitconfig
and apply to all your repositories. Without it it should set in.git/config
for just the repo you're in currently.The only documentation I can find on this is
submodule.<name>.ignore
at the git-config docs. I moved it from a .gitmodules file into my ~/.gitconfig and it's still working for me.您需要添加
到
.gitmodules
You need to add
to
.gitmodules
我已经在此处更详细地回答了这个问题。
只需运行
添加本地配置选项即可忽略这些更改。
I've answered this question here in greater detail.
Just run
to add a local config option to ignore those changes.
所以 git v1.7.2-rc2 有我想要的:
构建你自己的 git howto:
So git v1.7.2-rc2 has what I want:
Building your own git howto:
您可能不想将
ignore = dirty
添加到.gitmodules
,您可能希望对您希望忽略的更改更有选择性。为此,请将模式添加到
.git/submodule_foo/bar/info/exclude
,其中submodule_foo/bar/
是子模块的路径。这些模式与您添加到
.gitignore
的模式类似,根目录是子模块目录。例如,此模式忽略子模块submodule_foo/bar/
中的build
目录:You may not want to add
ignore = dirty
to.gitmodules
, you may want to be more selective about the changes you wished to ignore.To do that, add patterns to
.git/submodule_foo/bar/info/exclude
, wheresubmodule_foo/bar/
is the path of the submodule.The patterns are similar to the patterns you would add to
.gitignore
, with the root being the submodule directory. For instance, this pattern ignores thebuild
directory in the submodulesubmodule_foo/bar/
: