Git:我可以禁止在状态、差异等中列出“修改的内容”/脏子模块条目吗?

发布于 2024-09-09 04:02:34 字数 558 浏览 2 评论 0原文

有时(我认为是在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

时间海 2024-09-16 04:02:34

甚至可以为 .gitmodules 文件中每个添加的子模块设置忽略模式。

就在今天,我遇到了这个问题,并在找到解决方案后立即在我的博客中写了一篇文章: 如何忽略 git 子模块中的更改

它的要点:

添加子模块后,存储库的根目录中将会有一个名为 .gitmodules 的文件

只需在该 .gitmodules 文件中添加一行即可:

[submodule "bundle/fugitive"]
    path = bundle/fugitive
    url = git://github.com/tpope/vim-fugitive.git
    ignore = dirty

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:

Once you added a submodule there will be a file named .gitmodules in the root of your repository

Just add one line to that .gitmodules file:

[submodule "bundle/fugitive"]
    path = bundle/fugitive
    url = git://github.com/tpope/vim-fugitive.git
    ignore = dirty
失退 2024-09-16 04:02:34

您可以抑制两种更改通知。

第一个是未跟踪内容,当您对子模块进行更改但尚未提交这些更改时,就会发生这种情况。父存储库会注意到这些,并且 git status 相应地报告它:

modified:modules/media (untracked content)

您可以使用以下命令抑制这些内容:

[submodule "modules/media"]
   path = modules/media
   url = [email protected]:user/media.git
   ignore = dirty

但是,一旦您提交了这些更改,父存储库将再次注意到并相应地报告它们:

modified:   modules/media (new commits)

如果您也想抑制这些更改,则需要忽略所有更改

[submodule "modules/media"]
   path = modules/media
   url = [email protected]:user/media.git
   ignore = all

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:

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

[submodule "modules/media"]
   path = modules/media
   url = [email protected]:user/media.git
   ignore = all
小瓶盖 2024-09-16 04:02:34

更新:请参阅(并投票)nilshaldenwang回答关于向 .gitmodules 文件添加一个配置参数以忽略给定子模块的脏状态的可能性。

ignore = dirty

因此 git 1.7.2 已发布,并包含用于 status--ignore-submodules 选项。

来自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).

我想要的值是dirty

git status --ignore-submodules=dirty

我使用别名是因为我很懒:

alias gst='git status --ignore-submodules=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.

ignore = dirty

So git 1.7.2 is out and includes the --ignore-submodules option for status.

From 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.

git status --ignore-submodules=dirty

I use an alias because I'm lazy:

alias gst='git status --ignore-submodules=dirty'
赢得她心 2024-09-16 04:02:34

正如您所提到的,补丁 git 子模块:忽略摘要和状态的脏子模块 是在制作中。

Git 1.7.2-rc2 版本中还宣布:

Git v1.7.2 Release Notes (draft)
================================

Updates since v1.7.1
--------------------

git status”学习了“--ignore-submodules”选项。

含义:

git config --global diff.ignoreSubmodules dirty

将此视为一种选择并不完全是目前选择的方法

在本系列之后,我计划向 .gitmodules 添加一个配置选项“ignore”,可以将每个子模块设置为“all”、“dirty” ”、“未跟踪”或“无”(默认)。

git diff”和“git status”将为每个子模块使用该配置值。
使用“--ignore-submodule”会覆盖此默认值(并且将在其中添加新参数“none”以能够覆盖配置设置)。

为了避免每次该选项更改时都必须执行“git submdulesync”,我想首先在 .git/config 中搜索它。
如果在那里找不到,它将从 .gitmodules 中获取(如果存在)。

因此用户可以覆盖该设置,但如果他们不这样做,上游可以轻松更改它(例如,当子模块 .gitignore 已更新时,“ignore=untracked”不再需要,可以删除)。
此外,如果 .gitmodules 中的“ignore”条目在分支之间不同,切换分支也会立即生效。



Git 2.13(2017 年第 2 季度)提供了另一种使 git status(或任何 git 命令)忽略特定子模块的方法:

git config submodule.<name>.active false

请参阅“忽略 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:

Git v1.7.2 Release Notes (draft)
================================

Updates since v1.7.1
--------------------

"git status" learned "--ignore-submodules" option.

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).

"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).

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.


Another approach to make git status (or any git command) to ignore a particular submodule is available with Git 2.13 (Q2 2017):

git config submodule.<name>.active false

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

倦话 2024-09-16 04:02:34

您还可以

% git config [--global] submodule.ignore dirty

.git/config 文件中设置 submodule.ignore = dirty--global 将在您的 ~/.gitconfig 中设置忽略标志并应用于您的所有存储库。如果没有它,它应该在 .git/config 中为您当前所在的存储库进行设置。

我能找到的唯一文档是 git-config 文档。我将它从 .gitmodules 文件移到我的 ~/.gitconfig 中,它仍然对我有用。

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.

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.

慢慢从新开始 2024-09-16 04:02:34

您需要添加

ignore = dirty

.gitmodules

You need to add

ignore = dirty

to .gitmodules

勿忘初心 2024-09-16 04:02:34

我已经在此处更详细地回答了这个问题。

只需运行

git config --global diff.ignoreSubmodules dirty

添加本地配置选项即可忽略这些更改。

I've answered this question here in greater detail.

Just run

git config --global diff.ignoreSubmodules dirty

to add a local config option to ignore those changes.

云胡 2024-09-16 04:02:34

所以 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)

构建你自己的 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

So git v1.7.2-rc2 has what I want:

$ 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:

# 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
柒七 2024-09-16 04:02:34

您可能不想将 ignore = dirty 添加到 .gitmodules,您可能希望对您希望忽略的更改更有选择性。

为此,请将模式添加到 .git/submodule_foo/bar/info/exclude,其中 submodule_foo/bar/ 是子模块的路径。

这些模式与您添加到 .gitignore 的模式类似,根目录是子模块目录。例如,此模式忽略子模块 submodule_foo/bar/ 中的 build 目录:

# in .git/submodule_foo/bar/info/exclude:
/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, where submodule_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 the build directory in the submodule submodule_foo/bar/:

# in .git/submodule_foo/bar/info/exclude:
/build/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文