0

I have the following .gitignore file:

bin/*

My project has the following structure:

myFolder
----bin
-------file
----anotherFolder
----yetAnotherFolder

The .gitignore is located in the folder myFolder

Why is file still being committed?

3 Answers3

2

There are several ways to use .gitignore.

  1. Literal File Names, ex: .myFile

  2. Directories, ex: dir/

By adding the / in the end, the whole dir is ignored.

  1. Wildcard, ex: *.log

  2. Negation, ex: !example.log

  3. Double Asteriks, ex: **/logs or logs/**/*.log

In your case, you should probably just use bin/ and it will ignore everything from inside that dir.

More info here or here.

Lucas Campos
  • 1,860
  • 11
  • 17
  • How do I make it, so that certain files inside aren't ignored? –  Feb 27 '21 at 18:29
  • This does not answer the OPs question. From the question, it seems to be a confusion about adding and committing, and where the .gitignore has an effect. Nothing of what is written in this answer affects when a git commit command is issued. – Stefan Karlsson Feb 27 '21 at 21:58
0

Just put the below in your .gitignore instead of including the /*

bin

Will cause all files in that folder to be ignored.

If you have already committed the file then this won't work.

https://git-scm.com/docs/gitignore

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

If this is the case for you. Checkout this answer .gitignore after commit

James
  • 2,516
  • 2
  • 19
  • 31
0

If your file is updated during commits, it is because it is tracked.

The .gitignore has no effect on the process of making commits. The .gitignore file has the sole function of not adding files to be tracked. If you issue git add commands with wildcards, or for entire folders recursively, then your .gitignore will kick in and exclude those specified files.

If you wish to untrack a file, but still have it remain in your repo, then use

git rm --cached file

Be careful using git rm, it deletes files for real!

Stefan Karlsson
  • 1,092
  • 9
  • 21