Git:我可以禁止在状态、差异等中列出“修改内容”/脏子模块条目吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3240881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: can I suppress listing of 'modified content'/dirty submodule entries in status, diff, etc?
提问by kch
Somewhen (around the 1.6.x releases, I think) git became aware of changes inside submodules. That only serves to annoy me:
某个时候(我认为在 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
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.)
我可以把这个放进去~/.gitconfig
吗?从我的最初看来,我不能,而且我没有看到任何有希望的补丁。(我想我仍然可以做一个别名。)
采纳答案by kch
Update: See (and upvote) nilshaldenwang's answerregarding the possibility to add to the .gitmodules
file a config parameter for ignoring dirty state of a given submodule.
更新:请参阅(并投票)nilshaldenwang的关于是否可以将配置参数添加到文件以忽略给定子模块的脏状态的答案.gitmodules
。
ignore = dirty
So git 1.7.2 is out and includes the --ignore-submodules
option for status
.
所以Git的1.7.2过时了,包括--ignore-submodules
供选择status
。
From git help status
:
来自git help status
:
--ignore-submodules[=<when>] Ignore changes to submodules when looking for changes. <when> can be either "untracked", "dirty" or "all", which is the default. When "untracked" is used submodules are not considered dirty when they only contain untracked content (but they are still scanned for modified content). Using "dirty" ignores all changes to the work tree of submodules, only changes to the commits stored in the superproject are shown (this was the behavior before 1.7.0). Using "all" hides all changes to submodules (and suppresses the output of submodule summaries when the config option status.submodulesummary is set).
The value that I want is dirty
.
我想要的值是dirty
.
git status --ignore-submodules=dirty
I use an alias because I'm lazy:
我使用别名是因为我很懒:
alias gst='git status --ignore-submodules=dirty'
回答by NilsHaldenwang
There is even a possibility to set the ignore mode for every added submodule within the .gitmodules file.
甚至可以为 .gitmodules 文件中的每个添加的子模块设置忽略模式。
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
就在今天遇到这个问题,找到解决办法后立马在博客里写了一篇文章:如何忽略git子模块的变化
The gist of it:
它的要点:
Once you added a submodule there will be a file named
.gitmodules
in the root of your repository
添加子模块后,
.gitmodules
存储库的根目录中将有一个文件
Just add one line to that .gitmodules
file:
只需在该.gitmodules
文件中添加一行:
[submodule "bundle/fugitive"]
path = bundle/fugitive
url = git://github.com/tpope/vim-fugitive.git
ignore = dirty
回答by aleemb
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 and git status
reports it accordingly:
第一种是untracked content
当您对子模块进行更改但尚未提交时发生的情况。父存储库注意到这些并相应地git status
报告它:
modified: modules/media (untracked content)
modified: modules/media (untracked content)
You can suppress these with :
您可以使用以下方法抑制这些:
[submodule "modules/media"]
path = modules/media
url = [email protected]:user/media.git
ignore = dirty
However, once you commit those changes, the parent repository will once again take notice and report them accordingly:
但是,一旦您提交这些更改,父存储库将再次注意到并相应地报告它们:
modified: modules/media (new commits)
If you want to suppress these too, you need to ignore all
changes
如果您也想抑制这些,则需要忽略all
更改
[submodule "modules/media"]
path = modules/media
url = [email protected]:user/media.git
ignore = all
回答by VonC
As you mention, the patch git submodule: ignore dirty submodules for summary and statusis in the making.
正如您所提到的,补丁 git submodule: ignoredirty submodules for summary 和 status正在制作中。
Also announced in the Git 1.7.2-rc2release:
在Git 1.7.2-rc2版本中还宣布:
Git v1.7.2 Release Notes (draft)
================================
Updates since v1.7.1
--------------------
"
git status
" learned "--ignore-submodules
" option.
"
git status
"学习"--ignore-submodules
" 选项。
Meaning:
意义:
git config --global diff.ignoreSubmodules dirty
Regarding this as an option is not exactly the approach chosen for now:
After this series I am planning to add a config option '
ignore
' to.gitmodules
, which can be set for each submodule to either "all", "dirty", "untracked" or "none" (the default).
在本系列之后,我计划添加一个配置选项 '
ignore
' to.gitmodules
,它可以为每个子模块设置为“all”、“dirty”、“untracked”或“none”(默认值)。
"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).
" git diff
" 和 " git status
" 将为每个子模块使用该配置值。
使用“ --ignore-submodule
”会覆盖此默认值(并且将在此处添加新参数“none”以覆盖配置设置)。
And to avoid having to do "
git submdule sync
" every time that option changes, I would like to search for it in.git/config
first.
If it is not found there, it will be taken from.gitmodules
, if present.So users can override the setting but if they don't, upstream can change it easily (e.g. when a submodules
.gitignore
has been updated so that "ignore=untracked
" is no longer necessary anymore it can be removed).
Also switching branches will have an effect instantly if the 'ignore
' entry in.gitmodules
is different between branches.
为了避免
git submdule sync
每次更改选项时都必须执行“ ”,我想首先搜索它.git/config
。
如果在那里找不到它,它将从 中取出.gitmodules
(如果存在)。因此用户可以覆盖设置,但如果他们不这样做,上游可以轻松更改它(例如,当子模块
.gitignore
已更新以便ignore=untracked
不再需要“ ”时,可以将其删除)。
如果分支之间的 'ignore
' 条目.gitmodules
不同,切换分支也会立即生效。
Another approach to make git status (or any git command) to ignore a particular submodule is available with Git 2.13 (Q2 2017):
Git 2.13(2017 年第二季度)提供了另一种使 git status(或任何 git 命令)忽略特定子模块的方法:
git config submodule.<name>.active false
See more at "Ignore new commits for git submodule".
在“忽略 git 子模块的新提交”中查看更多信息。
回答by kjell_
You can also use
你也可以使用
% git config [--global] submodule.ignore dirty
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.
submodule.ignore = dirty
在您的.git/config
文件中设置。--global
将在您的中设置忽略标志~/.gitconfig
并应用于您的所有存储库。没有它,它应该.git/config
只为您当前所在的回购设置。
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.
我可以找到关于这个问题的唯一文档是submodule.<name>.ignore
在混帐配置文档。我将它从 .gitmodules 文件移动到我的 ~/.gitconfig 中,它仍然对我有用。
回答by Roman
You need to add
你需要添加
ignore = dirty
忽略 = 脏
to .gitmodules
到 .gitmodules
回答by kch
So git v1.7.2-rc2 has what I want:
所以 git v1.7.2-rc2 有我想要的:
$ git diff --ignore-submodules=dirty vendor # no output
$ git status --ignore-submodules=dirty vendor # On branch … nothing to commit (working directory clean)
Building your own git howto:
构建你自己的 git howto:
# get git
git clone git://git.kernel.org/pub/scm/git/git.git git
cd git
git checkout v1.7.2-rc2
# make git. beware of setting prefix
make configure
./configure --prefix=/usr/local
make
sudo make install
# you REALLY don't want to `make doc`, use this instead
sudo make quick-install-man
sudo make quick-install-html
回答by Devpool
回答by Flimm
You may not want to add ignore = dirty
to .gitmodules
, you may want to be more selective about the changes you wished to ignore.
您可能不想添加ignore = dirty
到.gitmodules
,您可能希望对要忽略的更改更有选择性。
To do that, add patterns to .git/submodule_foo/bar/info/exclude
, where submodule_foo/bar/
is the path of the submodule.
为此,请将模式添加到.git/submodule_foo/bar/info/exclude
,其中submodule_foo/bar/
是子模块的路径。
The patterns are similar to the patterns you would add to .gitignore
, with the root being the submodule directory. For instance, this pattern ignores the build
directory in the submodule submodule_foo/bar/
:
这些模式类似于您要添加到的模式.gitignore
,根目录是子模块目录。例如,此模式忽略build
子模块中的目录submodule_foo/bar/
:
# in .git/submodule_foo/bar/info/exclude:
/build/