当我在 Windows 上创建 .gitignore 文件时抛出“你必须输入文件名”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35245658/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 19:27:52  来源:igfitidea点击:

"You must type a file name" error thrown, when I create a .gitignore file on Windows

windowsgitgitignore

提问by leventunver

When I try to do this, I get the following error:

当我尝试这样做时,我收到以下错误:

gitignore error

gitignore 错误

Obviously, Windows Explorer doesn't allow me to create this type of file patterns. How can I overcome this problem?

显然,Windows 资源管理器不允许我创建这种类型的文件模式。我怎样才能克服这个问题?

回答by Philippe

I arrive a little late but will give you the trick!! ;-)

我来得有点晚,但会给你诀窍!;-)

In the File Explorer, call your file .gitignore.and it will remove the ending '.'

在文件资源管理器中,调用您的文件.gitignore.,它将删除结尾的“。”

Or use a text editor...

或者使用文本编辑器...

回答by IInspectable

Windows Explorer doesn't allow you to create files that consist essentially of a file extension only. This is because Windows Explorer has the option to hide file extensions, leaving you with a file you cannot see (see Why doesn't Explorer let you create a file whose name begins with a dot?). This is not a restriction of Windows itself, or the file system in use, though.

Windows 资源管理器不允许您创建基本上仅由文件扩展名组成的文件。这是因为 Windows 资源管理器可以选择隐藏文件扩展名,从而使您无法看到文件(请参阅为什么资源管理器不允许您创建名称以点开头的文件?)。不过,这不是 Windows 本身或正在使用的文件系统的限制。

To create a file named .gitignore, you will have to use another tool to create it. A common solution is to create a text file (e.g. test.txt), open it in Notepad, and select Save As...to rename the file to .gitignore.

要创建名为.gitignore的文件,您必须使用其他工具来创建它。一个常见的解决方案是创建一个文本文件(例如test.txt),在记事本中打开它,然后选择另存为...将文件重命名为.gitignore

The Windows command interpreter also allows you to create files without imposing the additional restrictions of Windows Explorer. A more direct solution would then be to create the file from the command line. This can be done using the following command:

Windows 命令解释器还允许您在不施加 Windows 资源管理器的额外限制的情况下创建文件。更直接的解决方案是从命令行创建文件。这可以使用以下命令完成:

copy NUL .gitignore



Note: When dealing with files that don't have a name, it's helpful to disable the option注意:处理没有名称的文件时,禁用“隐藏已知文件类型的扩展名”选项会很有帮助in Windows Explorer. Otherwise Windows Explorer might show files with no names, or hide them altogether.在 Windows 资源管理器中。否则 Windows 资源管理器可能会显示没有名称的文件,或者完全隐藏它们。

回答by gogog

in cmd,just type

在cmd中,只需输入

 echo. 2>.name_you_want

or

或者

. 2>.name_you_want

to create file.

创建文件。

if creating a dir,just type

如果创建目录,只需键入

mkdir .folder_name_you_want

回答by Rashid

Use command lineinstead.
I was also having the same error. The problem was .at the start of file or folder name.
So I created it by command line.

使用command line来代替。
我也有同样的错误。问题出.在文件或文件夹名称的开头。
所以我创建了它command line