在開發(fā)過程中如果在編輯.gitignore時疏漏,導致本不應該上傳至遠程倉庫的某個文件(夾)被提交,則可以使用如下方式解決
(只是從遠程倉庫中刪除,本地文件不受影響、不會被刪除)
1. 預覽想要刪除的文件
命令:git rm -r -n --cached 文件/文件夾名稱
由于增加了參數(shù) -n
,此時只是預覽涉及的文件,不會真正刪除
$ git rm -r -n --cached .idea
rm '.idea/.gitignore'
rm '.idea/DHEmbedding.iml'
rm '.idea/deployment.xml'
rm '.idea/inspectionProfiles/profiles_settings.xml'
rm '.idea/misc.xml'
rm '.idea/modules.xml'
rm '.idea/other.xml'
2. 執(zhí)行刪除操作
命令:git rm -r --cached 文件/文件夾名稱
$ git rm -r --cached .idea
rm '.idea/.gitignore'
rm '.idea/DHEmbedding.iml'
rm '.idea/deployment.xml'
rm '.idea/inspectionProfiles/profiles_settings.xml'
rm '.idea/misc.xml'
rm '.idea/modules.xml'
rm '.idea/other.xml'
刪除后 git 的狀態(tài):
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .idea/.gitignore
deleted: .idea/DHEmbedding.iml
deleted: .idea/deployment.xml
deleted: .idea/inspectionProfiles/profiles_settings.xml
deleted: .idea/misc.xml
deleted: .idea/modules.xml
deleted: .idea/other.xml
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
刪除對應的文件(夾)后記得編輯.gitignore,增加忽略項
3. 將刪除操作提交至遠程倉庫
commit文章來源:http://www.zghlxwxcb.cn/news/detail-503943.html
git commit -m "提交信息"
push文章來源地址http://www.zghlxwxcb.cn/news/detail-503943.html
git push
到了這里,關于git 刪除遠程倉庫中的文件(夾)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!