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

后端 未结 5 2033
眼角桃花
眼角桃花 2021-01-30 08:13

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

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

5条回答
  •  梦毁少年i
    2021-01-30 08:23

    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.

    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.

    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:

    copy NUL .gitignore
    


    Note: When dealing with files that don't have a name, it's helpful to disable the option "Hide extensions for known file types" in Windows Explorer. Otherwise Windows Explorer might show files with no names, or hide them altogether.

提交回复
热议问题