K
K
Kostya Bakay2016-06-30 20:36:26
Android
Kostya Bakay, 2016-06-30 20:36:26

Why doesn't .gitignore work for a new project in Android Studio?

I created a project which has a .gitignore file with a lot of content. After that, I initialized Git through the console and made a commit. But I still don't understand why it committed my files from .gitignore? What did I do wrong? The sequence of entered commands is in the screenshots.

.DS_Store

# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
out/
gen/

# Libraries used by the app
# Can explicitly add if we want, but shouldn't do so blindly.  Licenses, bloat, etc.
/libs


# Build stuff (auto-generated by android update project ...)
build.xml
ant.properties
local.properties
project.properties

# Eclipse project files
.classpath
.project

# idea project files
.idea/
.idea/.name
*.iml
*.ipr
*.iws

##Gradle-based build
.gradle
build/

fbdeaedf70064deb90e0eca1d3ff67fe.pnga9ec9ddc112346cc8dc28f92917b25df.png5599a0440d0d4d369d0f0fe42d4de6c9.pngfb09a4c5d8a64c7eb7fc34489096eb9e.png094dd568f7bd40fcb47162d7fc3a1300.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2016-06-30
@kostyabakay

You have a very old git -- update.
Are there sure to be no spaces or other characters at the end of lines in the .gitignore file?
https://git.kernel.org/cgit/git/git.git/tree/Docum...

Updates since v1.9 series
* Trailing whitespaces in .gitignore files, unless they are quoted
for fnmatch(3), eg "path\ ", are warned and ignored. Strictly
speaking, this is a backward-incompatible change, but very unlikely
to bite any sane user and adjusting should be obvious and easy.

https://git.kernel.org/cgit/git/git.git/tree/Docum...
Fixes since v2.0
* Mishandling of patterns in .gitignore that have trailing SPs quoted
with backslashes (eg ones that end with "\ ") has been
corrected.
(merge 97c1364be6b pb/trim-trailing-spaces later to maint).
https://git.kernel.org/cgit/git/git.git/tree/Docum...
Fixes since v2.4
* The codepaths that read .gitignore and .gitattributes files have been
taught that these files encoded in UTF-8 may have UTF-8 BOM marker at
the beginning; this makes it in line with what we do for configuration
files already.
(merge 27547e5 cn/bom-in-gitignore later to maint).

S
Sergey Kutylev, 2016-06-30
@sakutylev

For git ignore to work, it must be in the repository before you commit anything else.
git add .gitignore
git commit -m 'add .gitignore'
git push
git add .
git commit -m 'initial commit'
git push

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question