Cache Staheli
Cache Staheli

Reputation: 3663

Unity files not being ignored properly by git

I'm working with Unity in a group, and because of what I've read in several places, we put the following lines into our .gitignore

# =============== #
# Unity generated #
# =============== #
[Tt]emp/
[Oo]bj/
[Bb]uild
[Ll]ibrary/
sysinfo.txt
*.stackdump

# ============================================= #
# Visual Studio / MonoDevelop / Rider generated #
# ============================================= #
[Ee]xported[Oo]bj/
.vs/
/*.userprefs
/*.csproj
/*.pidb
/*.suo
/*.sln*
/*.user
/*.unityproj
/*.booproj
/.idea*/

# ============ #
# OS generated #
# ============ #
.DS_Store*
._*
.Spotlight-V100
.Trashes
ehthumbs.db
[Tt]humbs.db
[Dd]esktop.ini

When I clone the project, the working directory is clean, but as soon as I open this project in Unity, I see tons of files were marked as changed in git status: git status

Why are these files being added even though they are in the .gitignore?

Upvotes: 0

Views: 4160

Answers (2)

Fredrik
Fredrik

Reputation: 5108

That's a classic! If you added a gitignore after git started tracking your files, it won't release the files it is already tracking. You need to "reset" it by doing the following:

git rm -r --cached .
git add .
git commit -m "Gitignore now working!"

Will take care of everything. HOWEVER make sure you commit any changes before doing this, as they will otherwise be deleted.

Upvotes: 3

Secko
Secko

Reputation: 7716

Were they by any chance added before you created the .gitignore file?

If so, then remove them:

git rm --cached [file]

After that make a new commit with the changes. That is it, they will be removed and untracked from then on.

Upvotes: 5

Related Questions