【问题标题】:.gitignore files not working (ignore .DS_Store file in Mac OS).gitignore 文件不起作用(在 Mac OS 中忽略 .DS_Store 文件)
【发布时间】:2015-10-03 21:54:54
【问题描述】:

我在我的终端中通过此代码在我的~ 路径中创建了一个.gitignore 文件:

touch ~/.gitignore

并通过以下代码添加此文件和 git 定义排除文件:

git config --global core.excludesfile ~/.gitignore

然后使用以下命令删除我的所有.DS_Store 文件

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

(每个文件都已成功删除,如果我打开 xCode 并按提交,D 标签会出现在此文件附近)

在我提交之前,我通过以下命令将.DS_Store 添加到.gitignore 文件中:

echo .DS_Store >> ~/.gitignore

它也可以工作并将值写入文件,但它不工作。因为当我返回 xcode 并提交文件,然后返回 finder 并导航到文件夹并返回 xcode 时,我也可以在提交对话框中看到 .DS_Store 文件。

有人知道问题出在哪里吗?

【问题讨论】:

标签: xcode git


【解决方案1】:

执行后

git rm

您仍然需要提交这些更改

git commit -m "deleted all .DS files"

下次你向 git 询问差异时,这些文件将不再显示为已修改或“新”,因为它们在你的全局 gitignore 文件中

【讨论】:

  • [...] 你仍然需要提交这些更改 [...] 不; git rm DS_Store 应该足够了。无需创建提交。
  • 不。执行 git rm DS_Store 后,将暂存此文件的删除,但尚未提交。在实际删除文件之前,您必须执行 git commit。只要你不提交它,它仍然会在 git status 中显示为“已删除”(即使它现在在 gitignore 中)
  • 我认为我们指的是两个不同的东西。 git rm DS_Store 确实从工作树中删除了该文件,但您是对的,您需要为该文件创建一个提交,以便该文件不会出现在 git status 的输出中。
  • 确实,并且在问题“我也可以在提交对话框中看到.DS_Store文件。”中给出以下句子。,我猜测作者的问题是这些文件仍然显示的事实......
猜你喜欢
  • 2014-01-29
  • 2013-04-23
  • 2014-07-06
  • 2022-11-16
  • 2019-04-29
  • 2018-05-02
  • 2016-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多