12

I wish to ignore only one file without extension. I am able to ignore some files by names, but they all have extensions. Unfortunately I work with some files without extension that should not be ignored; thus, I can not use the solution provided here How do I add files without dots in them (all extension-less files) to the gitignore file?.

Does anybody know a way to achieve this? Any help is appreciated.

Community
  • 1
  • 1
cyntia
  • 201
  • 3
  • 8

2 Answers2

8

Based on this Gist https://gist.github.com/chichunchen/970a7e97c74a253a4503

Include the next 3 lines in the beginning of your .gitignore

# Ignore all
*
# Unignore all with extensions
!*.*
# Unignore all dirs
!*/

hope it helps

Kevin Oswaldo
  • 478
  • 5
  • 13
7

You might be making this more complex than it has to be. This could possibly be due to the answer you cited which ignores all extensionless files. To ignore a file without an extension does not appear to be very different than ignoring a file with an extension. To ignore your single file without an extension add this to your .gitignore:

relative/path/to/your/file

If the file had an extension, you would just add this:

relative/path/to/your/file.ext
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 5
    Thanks. I had tried that before but it did not work. Right now I just noticed that because the file was already in the remote repository. It did not ignore it. I had to remove it first and then it was able to ignore it without any problems. – cyntia Sep 09 '16 at 11:20
  • @cyntia Yes, if a file is already being tracked then you need to first use `git rm --cached` to remove it from the repository before adding it to your `.gitignore`. – Tim Biegeleisen Sep 09 '16 at 14:08
  • You can use `git ls-files -i --exclude-standard` to list them first. – Jovial Joe Jayarson Oct 19 '20 at 11:22