【问题标题】:git doesn't ignore 2 specifically named filesgit 不会忽略 2 个特别命名的文件
【发布时间】:2012-06-04 10:24:16
【问题描述】:

我想从提交中自动排除 2 个文件,它们是 git 存储库的一部分,但有一些更改,不应该是 github 存储库的一部分,因为它们有一些仅对我的本地系统有意义的更改和而不是其他开发者。

我将它们添加到 .git/info/exclude,希望 git 明白他不应该对它们进行更改:

# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
a.conf
b.conf
# *~

git status 仍将它们列为已提交:

# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   build/conf/a.conf
#   modified:   build/conf/b.conf
#

我不想在每次提交时定期取消暂存它们(有一次我可能会忘记),我该怎么做?

【问题讨论】:

  • 为什么不.gitignore
  • 您不能忽略正在跟踪的文件。您可能需要找到另一种管理本地系统特定信息的方法,例如拥有“模板”文件,您可以从中生成或手动编辑配置文件。
  • @maverik:如果exclude 不起作用,.gitignore 也不会。 exclude 的用例是此信息在本地,而 .gitignore 可以签入和共享。当您不想炸毁 .gitignore 时,请使用 exclude 获取本地内容。想象一个大型项目,每个开发人员都将他的排除项输入到.gitignore。它将变得无法管理......

标签: git gitignore


【解决方案1】:

您想要忽略跟踪文件的更改。这不能正确实现(如Charles Baileysays),.gitignore.git/info/exclude 都不能。

你需要使用git update-index:

git update-index --assume-unchanged build/conf/a.conf
git update-index --assume-unchanged build/conf/b.conf

将实现您想要的:文件始终假定不变。

如果您想再次跟踪这些文件中的更改,请使用--no-assume-unchanged

最后,如果你想知道哪些文件当前处于--assume-unchanged 模式,请向 git 询问

git ls-files -v | grep -e "^[hsmrck]"

【讨论】:

  • 非常适合我!
  • 此解决方案是否绑定到分支?让我们成为文件 1,文件 2 在分支 1 中标记为“假定不变”。然后结帐到branch2。这些文件是否也标记为“假定不变”?
  • @Leo 无法制作文件是因为该文件尚未被跟踪。您可以简单地转到 .git/info/exclude 并添加要排除的路径。
  • @eckes 无论如何要让所有分支机构都能使用它?如果我使用该命令,进行更改我无法切换分支并给我错误提交或存储它们
猜你喜欢
  • 2018-08-31
  • 1970-01-01
  • 2011-08-01
  • 2018-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多