.gitignore and git rm --cached will not track files

I have an Android project that has a test module that will delete and recreate .apk files in a subdirectory in the git directory.

I added them to .gitignore (directory, files explicitly and * .apk), and then I did

git rm -r --cached src/main/Tests/bin 

and git tells me:

 rm 'src/main/Tests/bin/Tests-debug-unaligned.apk' rm 'src/main/Tests/bin/Tests-debug.apk' rm 'src/main/Tests/bin/Tests.ap_' rm 'src/main/Tests/bin/classes.dex' 

i then

 git commit . -m "removed apk files" 

I run tests again that delete files and restore them. I run the git status and they appear as changed. It seems that .gitignore is not working. Here is my .gitignore file

 *ipr *iml *iws .gitignore out/ *apk src/main/Tests/bin src/main/Tests/bin/* src/main/Tests/bin/Tests-debug-unaligned.apk 
+6
source share
3 answers

I just tried my recipe and it worked for me.

 ~ % mkdir deleteme ~ % cd deleteme ~/deleteme % mkdir src src/main src/main/Tests src/main/Tests/bin ~/deleteme % touch src/main/Tests/bin/blah.apk ~/deleteme % git init Initialized empty Git repository in /Users/sri/deleteme/.git/ ~/deleteme (master*) % touch src/main/hello.txt ~/deleteme (master*) % git add . ~/deleteme (master*) % git commit -m "init" [master (root-commit) 0ef5764] init 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/Tests/bin/blah.apk create mode 100644 src/main/hello.txt ~/deleteme (master) % vi .gitignore ~/deleteme (master) % git rm -r --cached src/main/Tests/bin rm 'src/main/Tests/bin/blah.apk' ~/deleteme (master*) % git commit -m "removed" [master 5ca6456] removed 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/main/Tests/bin/blah.apk ~/deleteme (master) % touch src/main/Tests/bin/blah.apk ~/deleteme (master) % git status # On branch master nothing to commit (working directory clean) ~/deleteme (master) % 

Maybe gitconfig in some other directory (or global directive) that overrides what you have in the gitconfig that you specified. You did not indicate where this gitconfig is. See the man page for gitignore or online help for priority over various places where you can specify ignore rules. Human pages say ...

... the following order is priority, from highest to lowest (within the same priority level, last match, the pattern decides the outcome): Patterns read from the command line for those teams that support them.

  o Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build. o Patterns read from $GIT_DIR/info/exclude. o Patterns read from the file specified by the configuration variable core.excludesfile 
+1
source

I think you need to clear all your broken files using:

 git rm -r --cached . git add -A 

Then commit:

 git commit -m ".gitignore" 

But before you do this, be sure to make your changes.

+27
source

Have you tried just

 *.apk 

in .gitignore? If they have been tracked before, you will need to remove them and commit them before installing .gitignore. Once they disappear, add the entry to the .gitignore file, and it should work.

0
source

Source: https://habr.com/ru/post/898866/


All Articles