.gitignore和git rm --cached不会跟踪文件 [英] .gitignore and git rm --cached wont keep files from being tracked

查看:164
本文介绍了.gitignore和git rm --cached不会跟踪文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个android项目,它有一个测试模块,可以删除和重新创建git目录中的子目录中的.apk文件。

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

我已经添加了这些文件。 gitignore(目录,显式的文件和* .apk),然后我完成了

I have added these to .gitignore (the directory, the files explicitly, and *.apk ) and then I have done

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

和git告诉我:

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"

我再次运行测试,删除文件并重新创建它们。我运行git状态,并显示为已修改。看来.gitignore不起作用。这是我的.gitignore文件

I run the tests again which delete the files and the recreate them. I run git status and they show up as modified. It seems .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


推荐答案

它为我工作。

~ % 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) %  

也许在某个其他目录(或全局指令)中的gitconfig会覆盖你所说的gitconfig中的内容。你没有提到这个gitconfig位于哪里。请参阅gitignore手册页或联机帮助文档,了解可以指定忽略规则的各个位置的优先顺序。手册页说...

Perhaps the gitconfig in some other directory (or a global directive) that's overriding what you have in the gitconfig you have stated. You did not mention where this gitconfig is located. See the man page for gitignore or the online help docs for the precedence of the various locations where you can specify ignore rules. The man pages say...


...以下顺序的
优先级,从最高到最低(在一个级别内最后匹配的
模式决定结果):
从命令行读取的模式,用于那些支持
的命令。

...the following order of precedence, from highest to lowest (within one level of precedence, the last matching pattern decides the outcome): Patterns read from the command line for those commands 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


这篇关于.gitignore和git rm --cached不会跟踪文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆