首页 > 解决方案 > 如何忽略我没有写入权限的模块中的更改?

问题描述

我们有一个使用几个 git 模块的项目。遇到了一些问题,我对本地副本进行了一些更改。我没有对模块的提交权限,因此更改将一直保留,直到它们(通过其他方式)传播到正式版本,之后一切都会同步。

在那之前,有没有办法git忽略.gitignore这些.git/info/exclude变化的结果?我不知道该怎么称呼它们,但在 GitHub 中它们看起来像这样:

[] packages/local/Foobar        -Subproject commit-[lots of digits]
                                +Subproject commit-[lots of digits]-dirty

如果我有很多更改的文件,很容易忽略这些以取消勾选它们,最终我会收到 git/GitHub 错误。

标签: gitgithubgit-submodules

解决方案


git status --help中,有一个命令行标志可以忽略子模块:

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

如果您想永久忽略脏更改,请将忽略字段添加到您的子模块配置中.gitmodules如下所示:

[submodule "foo/bar"]
    path = foo/bar
    url = git://github.com/foo/bar.git
    ignore = dirty

如果您想忽略所有更改,请添加all而不是dirty

[submodule "foo/bar"]
    path = foo/bar
    url = git://github.com/foo/bar.git
    ignore = all

推荐阅读