bash 如何在 Windows 10 中创建 .gitignore 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48207907/
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 create a .gitignore file in Windows 10
提问by Rockstar5645
I tried to create a .gitignore file in my repository's root directory with the command
我尝试使用以下命令在我的存储库的根目录中创建一个 .gitignore 文件
$ touch .gitginore
in Git Bash.
在 Git Bash 中。
But when I looked at the file from the Windows Explorer. It says it's a text document. Isn't it supposed to be of the type File
?
但是当我从 Windows 资源管理器查看文件时。它说这是一个文本文件。不应该是那种类型File
吗?
回答by Youkool
touch .gitignore
works just fine. Windows detects it as a text file but git should works perfectly.
touch .gitignore
工作得很好。Windows 将其检测为文本文件,但 git 应该可以正常工作。
To be sure of it, you can type ls -la
and you should see all your files with their extensions, including .gitignore
just like in the following picture:
为了确保这一点,您可以输入ls -la
,您应该会看到所有带有扩展名的文件,包括.gitignore
如下图所示:
回答by Ben
but when I looked at the file from the windows explorer. It says it's a text document. Isn't it supposed to be of the type File
但是当我从 Windows 资源管理器中查看文件时。它说这是一个文本文件。它不应该是文件类型吗
Windows says your README is of type File
because it has no extension. In contrast, your .gitignore file has the extension .gitignore
which Windows has been configured to report (probably by the git-for-windows installer) the type Text Document
.
Windows 说您的自述文件属于类型,File
因为它没有扩展名。相比之下,您的 .gitignore 文件具有.gitignore
Windows 已配置为报告(可能由 git-for-windows 安装程序)类型的扩展名Text Document
。
回答by a.t.
Since the question does not specify any required tools, this contains a solution if you want to create a .gitignore
file using command prompt
or Windows Explorer
.
由于该问题未指定任何必需的工具,因此如果您想.gitignore
使用command prompt
或来创建文件,则该问题包含一个解决方案Windows Explorer
。
Command Prompt:
命令提示符:
In case one receives the following error message on a Windows 10 system in command prompt because touch
is a command of git bash:
如果在 Windows 10 系统上的命令提示符下收到以下错误消息,因为touch
是 git bash 的命令:
'touch' is not recognized as an internal or external command, operable program or batch file.
'touch' 不是内部或外部命令,也不是可运行的程序或批处理文件。
You can either use the following command in command prompt (cmd):
您可以在命令提示符 (cmd) 中使用以下命令:
echo. > .gitignore
or
或者
type nul > .gitignore
as indicated here: Windows equivalent of 'touch' (i.e. the node.js way to create an index.html). This procedure will not generate a Text Document
as indicated in the problem statement, but a file that appears to not have any extension.
如此处所示:Windows 等效于“触摸”(即创建 index.html 的 node.js 方式)。此过程不会生成Text Document
问题陈述中所指示的文件,而是生成一个似乎没有任何扩展名的文件。
Windows Explorer:
Windows资源管理器:
If you try to do it in Windows 10 Explorer by clicking right mouse button(RMB)>New>Text Document
and you try to name it .gitignore
you can receive the following error:
如果您尝试在 Windows 10 资源管理器中通过单击鼠标右键 (RMB)>New> 来执行此操作Text Document
并尝试为其命名,.gitignore
您可能会收到以下错误:
You must type a file name.
您必须键入文件名。
This can be overcome by giving it the filename .gitignore.
. So if your git repository folder contains a folder named output
which you want to suppress/not sync, you can add it to the .gitignore
by editing the .gitignore.
file with a text editor and adding a line that contains /output
. This last procedure generates a file which is also a .txt
document as indicated in the problem statement, but as mentioned by @hobbs and @Youkool that is not a problem for git. Furthermore, the last procedure is verified in Windows 10 with git version 2.16.1.windows.4
.
这可以通过给它文件名来克服.gitignore.
。因此,如果您的 git 存储库文件夹包含一个output
您想要禁止/不同步的文件夹,您可以.gitignore
通过.gitignore.
使用文本编辑器编辑文件并添加一行包含/output
. 最后一个过程会生成一个文件,该文件也是.txt
问题陈述中指示的文档,但正如@hobbs 和@Youkool 所提到的,这对 git 来说不是问题。此外,最后一个过程在 Windows 10 中通过git version 2.16.1.windows.4
.
回答by Raju Athokpam
Please refer to How do I manually create a file with a . (dot) prefix in Windows? For example, .htaccess.
请参阅如何手动创建带有 . Windows 中的(点)前缀?例如, .htaccess。
Reproducing for your easy access: In File Explorer, right click anywhere and create a new file. Type the new filename as .something.
(notice the appended period) and press Entertwice, job done.
复制以方便访问:在文件资源管理器中,右键单击任意位置并创建一个新文件。键入新文件名.something.
(注意附加的句点)并按Enter两次,工作完成。