Visual Studio files copied to GitHub but listed in .gitignore
I cannot figure out what I am missing in trying to prevent the Visual Studio 2019 Team Explorer from copying files to GitHub when the .gitignore file lists them.
My .gitignore file is in the same directory as is the .git directory. It is in toto:
# Binaries
/x64/
# VS log files
*.log
*.tlog
# Visual Studio files and folder
/.vs/When I wish to commit changes, VS displays the following:
I do not want to commit Tetris_Game.exe, nor any .tlog or .log files, nor anything from the .vs folder. However, as you can see, those files and directory are listed for commitment.
What am I missing which has got to be very obvious?
2 Answers
This is because all these files with extension .exe, .tlog and .log would be present on your git repository as well. So any change to these files will be tracked for sure.
To make .gitignore work as expected, perform below steps,
- Delete all the files you want to ignore locally.
- Then commit and push. Now your repository and .gitignore file are in consistent state.
- Restart VS and perform a pull.
- Build your solution/project.
Now observe your git change window, these files should not be listed, though generated in your local machine.
The leading slash in /.vs/ and /x64/ means those are absolute paths from the root of the filesystem.
For a Windows PC with the repo pulled to anywhere on the C: drive, your .gitignore would ignore files in C:\.vs\ and C:\x64\.
Remove the leading slash and just leave them as .vs/ and x64/.
Then they will be interpreted as paths that are relative to the .gitignore file.