如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?


当前回答

如果您无法删除这些文件,因为它们有暂存的更改,请使用:

git rm --cached -f *.DS_Store

其他回答

初始化存储库时,跳过包含

-u

这不应该是个问题。

从存储库中删除现有的.DS_Store文件:

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

添加此行:

.DS_Store

到文件.gitignore,该文件可以在存储库的顶层找到(如果文件还不存在,则创建该文件)。您可以在顶部目录中使用以下命令轻松完成此操作:

echo .DS_Store >> .gitignore

然后将文件提交到repo:

git add .gitignore
git commit -m '.DS_Store banished!'

步骤1

这将删除目录(包括子目录)中的每个.DS_Store文件

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

步骤2

将此添加到.gitignore以防止根目录和每个子目录中的任何DS_Store文件进入git!

**/.DS_Store

从git文档中:

前导“**”后接斜杠表示所有目录中的匹配。例如,“**/foo”与任何位置的文件或目录“foo”匹配,与模式“foo“相同。“**/foo/bar”匹配直接位于目录“foo”下的文件或目录“bar”。

有时.DS_Store文件位于远程存储库中,但在本地项目文件夹中不可见。要解决此问题,我们需要删除所有缓存的文件并再次添加。

步骤1:将其添加到.gitignore文件中。

# Ignore Mac DS_Store files
.DS_Store
**/.DS_Store

步骤2:删除缓存的文件,然后使用这些命令再次添加。

git rm -r --cached .
git add .
git commit -am "Removed git ignored files"
git push -f origin master

这对我很有用,上面有两个答案:

$git rm--缓存-f*.DS_Store$gitcommit-m“过滤器分支--索引过滤器'git rm--缓存--忽略取消匹配.DS_Store“$git推送原始主机--强制