- Home /
.gitignore not ignoring Library. What's the correct way to do it?
First time Version Controlling, I'm using Bitbucket and SourceTree on Windows.
I created a new project, cloned it as a new repository, committed the changes. Then, I tried to gitignore the "Library" folder (since I've read I should) by using this: https://gist.github.com/thebeardphantom/982bab3b026571ab7970
Here's where I think I did something wrong:
I went to the project folder [User/Documents/MyProject] and created a text document named ".gitignore" with the content above. Having done that, I went back to SourceTree and committed the change.
Now, by doing that, should I expect the metadata files to get ignored? because they didn't. Actually, it had no effect on the repository. I tried different versions of ".gitignore" but all handed the same results. So my question is:
TL;DR: What is the correct way to .gitignore?
Was the Library folder already committed when you added it to the gitignore file? The ignore file can't make it ignore files that are already being tracked. When using git with Unity you should set up gitignore before the initial commit (or make sure you only commit stuff in ProjectSettings & Assets folders).
If this is the problem then it can be got around. See eg http://stackoverflow.com/questions/1274057/making-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore (but make sure you read it carefully)
Thanks, that appears to be the case! I removed the Library folder (following the instructions provided), but now everytime I make changes in Unity, the "Library" metadata still appears under "Unstaged Files", pending and waiting to be committed, is that normal?
Do mean just the Library.meta
file? If so, it's probably still being tracked. It won't be removed from the index when you remove Library
or Library/*
.
Putting /Library into .gitignore should work.
Two things: - You wrote: ".gitignored" once in your question. Is this just a typo? - You said you created a text document named ".gitignore". It could be that this file has the extension ".txt" (windows) where it should have not (just ".gitignore"). So make sure Windows is showing you ALL file extensions and check if your file has one and remove it.
It's a typo, sorry.
".gitignore" does indeed have a ".txt" extension, and this was the very problem from the beginning. I changed its extension to just ".gitignore" by following these 4 steps: http://stackoverflow.com/a/12298593
"Library" is finally getting ignored. Thanks!
If you follow the link to look at the .gitignore
they're using, it does things the other way - removing everything then adding the things you do want. So it shouldn't be necessary to explicitly ignore the Library folder or its meta file.
Good point about checking that the basics are working though!
I'm using TortoiseGit, so ignoring a folder (and it's content) is only one right click away :)
Btw: Unity creates only .meta files in my Assets folder, nowhere else (there is no Library.meta).
Answer by Naserano · Jan 13, 2016 at 09:55 AM
Problem: .gitignore has no effect.
Reason: Its extension is ".txt" -> [.gitignore.txt]
Solution: Change it to ".gitignore" -> so it can become just [.gitignore]
This can be achieved in 3 simple steps:
Open your project folder [User/Documents/MyProject]
Hold SHIFT, right click anywhere in the folder you're in, then select Open command window here
Then rename the file in the command line, with:
ren gitignore.txt .gitignore
Thanks to @BonfireBoy and @saschandroid
I had this same problem and couldn't see it because Windows 10 was hiding the file extension ".txt", if it hadn't I would have spotted it immediately. Then it actually wouldn't allow me to rename the file to ".gitignore" saying that "A file name is required". Thanks, Windows. Thanks for making simple things difficult.
I opened GIT bash in the folder and ran
mv .gitignore.txt .gitignore
and it resolved my problem.
Your answer
Follow this Question
Related Questions
Unity Git - Ignore Library 2 Answers
How to fix /Library/ conflicts in GitHub repo for Unity project? 1 Answer
UnityYAMLMerge: File is not a valid text serialization YAML file 1 Answer
Build platform doesn't stick when using VCS (Git) 2 Answers
Unity and git - issue with constantly modified prefabs and scenes 0 Answers