我有一个android项目,它有一个测试模块,可以在git目录的子目录中删除并重新创建.apk文件.
我已将这些添加到.gitignore(目录,显式文件和*.apk),然后我就完成了
git rm -r --cached src/main/Tests/bin
Run Code Online (Sandbox Code Playgroud)
和git告诉我:
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'
Run Code Online (Sandbox Code Playgroud)
我然后
git commit . -m "removed apk files"
Run Code Online (Sandbox Code Playgroud)
我再次运行测试,删除文件并重新创建它们.我运行git status并显示为已修改.看来.gitignore没有用.这是我的.gitignore文件
*ipr
*iml
*iws
.gitignore
out/
*apk
src/main/Tests/bin
src/main/Tests/bin/*
src/main/Tests/bin/Tests-debug-unaligned.apk
Run Code Online (Sandbox Code Playgroud)
Gen*_*uro 28
我认为您需要使用以下方法清除所有错误的文件:
git rm -r --cached .
git add -A
Run Code Online (Sandbox Code Playgroud)
然后提交:
git commit -m ".gitignore"
Run Code Online (Sandbox Code Playgroud)
但请确保在执行此操作之前提交更改.
我刚刚尝试了你的食谱,它对我有用。
~ % 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) %
Run Code Online (Sandbox Code Playgroud)
也许其他目录(或全局指令)中的 gitconfig 会覆盖您所声明的 gitconfig 中的内容。您没有提到这个 gitconfig 所在的位置。请参阅 gitignore 的手册页或在线帮助文档,了解可以指定忽略规则的各个位置的优先级。手册页说...
...以下优先级顺序,从最高到最低(在一个优先级内,最后一个匹配模式决定结果):从命令行读取支持它们的命令的模式。
Run Code Online (Sandbox Code Playgroud)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