如何解决这个问题?
我认为你遇到的问题是,在之前的某个提交中,你不小心将.DS_Store
文件添加到了代码库中。当然,一旦一个文件被跟踪到你的代码库中,即使它与适用的.gitignore文件中的条目匹配,它也会继续被跟踪。
你需要手动删除已添加到代码库中的.DS_Store
文件。你可以使用
git rm --cached .DS_Store
移除后,git 应该会忽略它。你只需要在根目录下的 .gitignore
文件中添加以下代码:.DS_Store
。不要忘记句号!
git rm --cached .DS_Store
仅从当前目录中删除.DS_Store
文件。您可以使用
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
从仓库中删除所有的.DS_Stores
。
提示:由于您可能永远不想包括.DS_Store
文件,因此请制定全局规则。首先,在某个地方创建全局.gitignore
文件,例如
echo .DS_Store >> ~/.gitignore_global
现在告诉Git对所有仓库使用它:
git config --global core.excludesfile ~/.gitignore_global
这个页面帮助我回答了你的问题。
将**/.DS_Store
添加到.gitignore
文件中,以忽略子目录中的.DS_Store文件。
如果.DS_Store
已经提交:
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
忽略它们在所有存储库中的存在:(有时命名为._.DS_Store
)echo ".DS_Store" >> ~/.gitignore_global
echo "._.DS_Store" >> ~/.gitignore_global
echo "**/.DS_Store" >> ~/.gitignore_global
echo "**/._.DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
git rm --cached your_file
命令。 - ronald8192find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
,来自:
https://dev59.com/WGMl5IYBdhLWcg3wcmvD#_qugEYcBWogLw_1bRJFU - ronald8192find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
- Mehmet Kaplanprintf "%b\n" ".DS_Store\n._.DS_Store\n**/.DS_Store\n**/._.DS_Store\n" >> ~/.gitignore_global && git config --global core.excludesfile ~/.gitignore_global
- ikaeromprintf "%b\n" ".DS_Store\n._.DS_Store\n**/.DS_Store\n**/._.DS_Store\n" >> ~/.gitignore_global && git config --global core.excludesfile ~/.gitignore_global
- undefined.gitignore
在你的应用程序的根目录中,只需编写:
**/.DS_Store
在这里。这将永远不允许 .DS_Store 文件偷偷潜入你的 Git。
但是,如果它已经存在,可以在终端中输入以下命令:
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
接着提交并推送更改,以从您的远程存储库中删除 .DS_Store 文件:
git commit -m "Remove .DS_Store from everywhere"
git push origin master
现在需要将 .DS_Store 添加到你的 .gitignore 文件中,然后再使用最后两个代码片段进行提交和推送(git commit..., git push...)。
*
或 **
。这是告诉 shell 如何导航目录的一种方式。此 stackoverflow 答案完整地解释了它 https://dev59.com/jV4c5IYBdhLWcg3wOoAH#28199633 - El'Magnificofind . -name '.DS_Store' -type f -delete
递归删除所有创建的 .DS_Store 文件。 - Robby Alvian Jaya Muliagit rm --cached path/to/file/here
。 - Sgnl只需将此内容放在新的一行中的 .gitignore
文件中即可。
**/.DS_Store
来自git文档
- 以斜杠跟着一个星号 "**" 表示匹配所有目录。例如,"**/foo" 匹配文件或目录 "foo" 在任何地方,和模式 "foo" 相同。"**/foo/bar" 匹配直接在目录 "foo" 下的任何位置上 "bar" 文件或目录。
**/.DS_Store
只是写成 .DS_Store
的一种更复杂的方式。只有在想要 gitignore 特定路径模式时才需要双星号,无论它出现在哪里。例如,**/foo/.DS_Store
只会隐藏 foo
子目录中的 .DS_Store
文件(不管 foo
位于何处)。 - orlp第一步,删除所有的*.DS_store
文件。可以运行以下命令:
git rm -f *.DS_Store
但要注意,如果你输错了,rm -f
命令可能会有点危险!
*.DS_Store
.DS_Store
加入到 .gitignore 文件中。这对我有用!
将*.DS_Store
添加到您的.gitignore文件中。对于我来说,这样做非常完美。
你也可以在auco的答案中添加--cached
标志,以保留本地 .DS_store 文件,就像 Edward Newell 在他的原始回答中提到的那样。 修改后的命令如下:find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch
..祝福和感谢!
步骤1:使用以下命令删除现有文件
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
步骤2:在.gitignore文件中添加.DS_Store
步骤3:提交您的更改到.gitignore git add .gitignore git commit -m "removed .DS_Store"
$ git rm ./*.DS_Store
- 从git中删除所有的.DS_Store文件$ echo \.DS_Store >> .gitignore
- 忽略以后的.DS_Store文件提交并推送