Ray
Ray

Reputation: 4929

gitignore not working with spaces in folder name

I'm doing a git status and I have the following file that shows up in the "Changes not staged for commit"

/GTCS/External Assemblies/Alstom.ApplicationBroker.Toolkit.dll

So I added the exact text above to the .gitignore file.

But it still shows up in the Changes not staged for commit when I do a git status.

I think it is because of the space in the folder name External Assemblies or maybe the fact that I placed a forward slash at the beginning?

I tried putting a backwards slash immediately after the word External but that does not work. Always appears as not staged.

Upvotes: 1

Views: 3168

Answers (2)

axiac
axiac

Reputation: 72186

If the file appears in the "Changes not staged for commit" area it means the file is already tracked by Git.

Git uses .gitignore only when adding new files to the repository (i.e. git add). Your file is already tracked, adding its name now in .gitignore doesn't change anything.

If you want to ignore the file when it is already tracked you have to:

  1. add its name/path to .gitignore and
  2. remove the file from the repository.

The second part is as easy as:

git rm --cached /GTCS/External Assemblies/Alstom.ApplicationBroker.Toolkit.dll

After you commit the removal the file will not appear in the output of git status any more.


N.B. The space in the name is not related in any way to the issue.

Upvotes: 2

Milan Chheda
Milan Chheda

Reputation: 8249

Try /GTCS/External\ Assemblies/Alstom.ApplicationBroker.Toolkit.dll. There should be a slash before the space.

Upvotes: 1

Related Questions