# 忽略所有以 .a 结尾的文件
*.a
# 不能忽略所有 lib.a 文件
!lib.a
# 仅仅忽略当前目录下的 TODO 文件
/TODO
# 忽略 build 目录下的所有文件
build/
# 仅仅忽略 doc 一个目录下的所有 .txt 文件
doc/*.txt
# 忽略 doc 目录下(包括子目录)的所有 .pdf 文件
doc/**/*.pdf
比如我这里想忽略掉available_models文件夹下的所有pt文件,
因为这个忽略文件是项目早已创建,并进行了git管理,忽略文件是后续根据需求加的,因此需要先删除git里面的跟踪缓存,不然忽略文件不会起作用。
删除缓存:git rm -r -f --cached .
然后 git add .
接着查看缓存区域,看.gitignore忽略的内容是否没有在: git ls-files
没有在就表示其作用了,然后再提交:git commit -m ".gitignore重写缓存"
最后push:git push
$ git add .
warning: adding embedded git repository: available_models
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint: git submodule add <url> available_models
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint: git rm --cached available_models
hint:
hint: See "git help submodule" for more information.
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'git@github.com:taozhuowei/StoreMyToys.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
解决办法,先pull,将项目拉下来。git pull --rebase origin master
,
然后再推,git push
。
因篇幅问题不能全部显示,请点此查看更多更全内容