git ignore 已经跟踪的文件
故事背景:
之前把不属于项目的文件提交了,现在想把它从项目中移除,怎么办?
办法:
git rm --cached filename
Git - .gitignore怎么忽略已经被版本控制的文件
git filter-branch --force --index-filter'git rm --cached --ignore-unmatch path-to-your-remove-file'--prune-empty --tag-name-filtercat-- --all
例子
想删除pycharm 的项目文件夹 .idea/
git filter-branch --force --index-filter'git rm -r --cached --ignore-unmatch .idea/'--prune-empty --tag-name-filtercat-- --all
Rewrite 3211102c107199d3d4287327ec8149b8ba567eda (41/41) (57 seconds passed, remaining 0 predicted)
Ref 'refs/heads/master' was rewritten
Ref 'refs/heads/master-lab' was rewritten
Ref 'refs/remotes/origin-lab/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
Ref 'refs/remotes/origin/gitlab_hook' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
$ git push origin --force --all
Enumerating objects: 356, done.
Counting objects: 100% (356/356), done.
Delta compression using up to 4 threads
Compressing objects: 100% (350/350), done.
Writing objects: 100% (354/354), 2.46 MiB | 2.32 MiB/s, done.
Total 354 (delta 120), reused 0 (delta 0)
remote: Resolving deltas: 100% (120/120), completed with 1 local object.
To gitlabe2.ext.net.nokia.com:lingxie/python-learn-2.git
+ 3211102...8211c18 master -> master (forced update)