如何忽略图标?在 git 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17556250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore Icon? in git
提问by taiansu
While trying to setup a dropbox folder with git, I saw a "Icon\r" file which is not created by me. I try to ignore it in the ~/.gitignore file. But adding Icon\r
Icon\r\r
Icon?
won't work at all.
在尝试使用 git 设置 dropbox 文件夹时,我看到了一个不是我创建的“Icon\r”文件。我尝试在 ~/.gitignore 文件中忽略它。但是添加Icon\r
Icon\r\r
Icon?
根本不起作用。
采纳答案by eldes
The Icon? is the file of OS X folder icon. The "?" is a special character for double carriage return (\r\r).
图标?是 OS X 文件夹图标的文件。这 ”?” 是双回车的特殊字符 (\r\r)。
Open terminal and navigate to your repository folder, then type:
打开终端并导航到您的存储库文件夹,然后键入:
printf "Icon\r\r" > .gitignore
Or, if the .gitignore file exists and is not empty:
或者,如果 .gitignore 文件存在且不为空:
printf "Icon\r\r" >> .gitignore
UPDATE
更新
As suggested by robotspacer, according to hidn's explanation, better then:
正如robotsspacer所建议的,根据hidn的解释,最好是:
printf "Icon[\r]" >> .gitignore
回答by Dharma
You can use vimas well.
您也可以使用vim。
vim .gitignore
- in a new line write
Icon
, then - press ctrl+vand then press Enter
- repeat step 3
- save and exit (shortcut: ZZ)
vim .gitignore
- 在一个新行写
Icon
,然后 - 按ctrl+v然后按Enter
- 重复步骤 3
- 保存并退出(快捷键:ZZ)
Now you should have Icon^M^M
and it's done :)
现在你应该已经Icon^M^M
完成了:)
For a smarter use you could add it to your gitignore global config file in ~/.gitignore_global
.
为了更智能的使用,您可以将其添加到 .gitignore 全局配置文件中~/.gitignore_global
。
回答by hidn
"Icon[\r]"
is probably a better alternative.
In vim, you just put Icon[^M]
, which is Icon[
followed by CtrlV, Enterthen ]
.
"Icon[\r]"
可能是更好的选择。
在 vim 中,您只需放置Icon[^M]
,Icon[
后跟CtrlV,Enter然后]
。
The problem with "Icon\r\r"
is EOL conversion.
问题"Icon\r\r"
在于 EOL 转换。
The whole line is actually "Icon\r\r\n"
, counting line ending. Based on your setup, CRLF
may be converted to LF
on commit, so your repo will actually have "Icon\r\n"
. Say you sync the changes to another repo. You will get "Icon\r\n"
in that working directory, which ignores Icon
but not Icon^M
. If you further edit .gitignore
and commit it there, you will end up with "Icon\n"
- completely losing \r
.
整行实际上是"Icon\r\r\n"
,计数行结束。根据您的设置,CRLF
可能会转换为LF
提交时,因此您的存储库实际上将具有"Icon\r\n"
. 假设您将更改同步到另一个存储库。您将进入"Icon\r\n"
该工作目录,该目录忽略Icon
但不忽略Icon^M
. 如果你进一步编辑.gitignore
并在那里提交,你最终会"Icon\n"
- 完全丢失\r
.
I encountered this in a project where some develop on OS X while some on Windows. By using brackets to separate \r
and the line ending, I don't have to repeat \r
twice and I don't worry about EOL conversion.
我在一个项目中遇到了这个问题,有些在 OS X 上开发,有些在 Windows 上开发。通过使用括号分隔\r
和行尾,我不必重复\r
两次,也不用担心 EOL 转换。
回答by rjatkinson
The best place for this is in your global gitignore configuration file. You can create this file, access it, and then edit per the following steps:
最好的地方是在你的全局 gitignore 配置文件中。您可以创建此文件,访问它,然后按照以下步骤进行编辑:
>> git config --global core.excludesfile ~/.gitignore_global
>> git config --global core.excludesfile ~/.gitignore_global
>> vim ~/.gitignore_global
>> vim ~/.gitignore_global
press ito enter insert mode
按i进入插入模式
type Icon
on a new line
键入Icon
一个新行
while on the same line, ctrl+ v, enter, ctrl+ v, enter
而在同一行,ctrl+ v, enter, ctrl+ v,enter
press esc, then shift+ ;then type wqthen hit enter
按esc,然后shift+;然后输入wq然后点击enter
回答by taiansu
The Icon? is the file of OSX folder icon. It turn out that \r
is actually CRLF. So I use ruby to add the line to .gitignore
file. Open terminal and navigate to home
folder, then:
图标?是 OSX 文件夹图标的文件。事实证明,这\r
实际上是 CRLF。所以我使用 ruby 将该行添加到.gitignore
文件中。打开终端并导航到home
文件夹,然后:
> irb
>> f = File.open(".gitignore", "a+") #<File:.gitignore>
>> f.write("Icon\r\r") # output a integer
>> f.close
>> exit
回答by AAGD
For me this worked in TextMate: Icon<CR><CR>
. The <CR>
is a carriage return character, which is at ctrl-alt-return
on the keyboard. You can also find it in the standard Character Viewer app searching for cr
. Please note that the <CR>
is an invisiblecharacter, so it's only visible if the editor is set up to show them.
对于我这个曾在TextMate的:Icon<CR><CR>
。该<CR>
是一个回车符,这是在ctrl-alt-return
键盘上。您还可以在标准 Character Viewer 应用程序中搜索cr
. 请注意,这<CR>
是一个不可见的字符,因此只有在编辑器设置为显示它们时才可见。