I am using Git in Android Studio on a OS X machine, and I would like to have a personal .gitignore
file that overrides the .gitignore
that are in the project (I want mine to ignore .iml
files). Can this be done and how?
I have tried to create a .gitignore
file in my home dir with the following lines in:
# Android Studio .*.iml *.iml
And the I have used this command to make git use my file git config --global core.excludesfile ~/.gitignore
, but it does not work.
Any ideas?
For those who don't mind modifying the . gitignore file, you can override a rule by adding ! in front of a filename or folder. Use * to select the files in a folder and ** to select the files in subfolders recursively.
You can have multiple . gitignore , each one of course in its own directory. To check which gitignore rule is responsible for ignoring a file, use git check-ignore : git check-ignore -v -- afile .
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use git rm --cached.
Instead of creating a new .gitignore
file, you should use the .git/info/exclude
file to setup ignore rules specific to your clone of the repo.
So, basically, go to your project root, and run
cd $PROJECT_ROOT echo "*.iml" >> .git/info/exclude
Note that the the pattern *.iml
will take care of files of kind .*.iml
as well, so you can make do with one ignore rule.
Also, this complements the existing ignore rules in .gitignore
and ignore rules of .gitignore
will still be applied.
It seems you are already tracking the .iml
files in your Git repo, so you can try removing them from Git using
git rm -r *.iml git commit -m "removed *.iml"
Note that this will untrack them from the master repository as well once you do a push.
Otherwise, you can use git update-index --assume-unchanged <filename>
to ignore changes to those files locally. And afterwards, the gitignore rules should work all right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With