在开发实际的开发中,我们将某些文件加入.gitignore,但是怎么操作都是无效的。其实在最初git add时并没有更改.gitignore,.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。解决方法就是先把本地缓存删除(改变成未track状态),然后再提交,具体如下图:
PS D:\WWW\landscape> git rm -r --cached .
rm '.env .example'
rm '.gitignore'
rm 'README.md'
rm 'babel.config.js'
rm 'config/build.js'
rm 'config/config.js'
rm 'config/dev.js'
rm 'package-lock.json'
rm 'package.json'
rm 'public/Blob.js'
rm 'public/Export2Excel.js'
rm 'public/favicon.ico'
rm 'public/index.html'
rm 'public/logo/logo-min.png'
rm 'public/logo/logo.png'
rm 'public/user.svg'
rm 'src/App.vue'
rm 'src/assets/css/waf/style.css'
rm 'src/assets/css/waf/swiper.css'
rm 'src/assets/images/login-bg.jpg'
rm 'src/assets/images/logo.png'
rm 'src/assets/js/Blob.js'
rm 'src/assets/js/Export2Excel.js'
rm 'src/components/admin.vue'
rm 'src/components/header.vue'
rm 'src/components/slider.vue'
rm 'src/directive/index.js'
rm 'src/directive/permission/hasPermi.js'
rm 'src/main.js'
rm 'src/request/index.js'
rm 'src/router/index.js'
rm 'src/store/getters.js'
rm 'src/store/modules/app.js'
rm 'src/store/modules/user.js'
rm 'src/store/store.js'
rm 'src/utils/aes.js'
rm 'src/utils/menuList.js'
rm 'src/utils/request.js'
rm 'src/view/data/baw.vue'
rm 'src/view/data/db.vue'
rm 'src/view/login/identifyA.vue'
rm 'src/view/login/index.vue'
rm 'src/view/operatelog/index.vue'
rm 'src/view/personal/info.vue'
rm 'src/view/personal/password.vue'
rm 'src/view/system/editPower.vue'
rm 'src/view/system/powerList.vue'
rm 'src/view/system/userList.vue'
rm 'vue.config.js'
PS D:\WWW\landscape> git add .
PS D:\WWW\landscape> git commit -m 'xxx'
[fraud 585f0ca] xxx
6 files changed, 545 insertions(+), 13625 deletions(-)
delete mode 100644 package-lock.json