git如何移除某資料夾的版本控制
阿新 • • 發佈:2019-02-03
http://www.tuicool.com/articles/NfEzeq
目錄結構如下
project
bin
lib
src
......
執行如下的操作
git add .
git commit -m "add bin/ lib/ src/"
git push origin master
突然發現原來 lib
目錄不需要提交到版本庫,但是現在遠端已經存在該目錄,what should I do.(吐出去的東西還能收回來嗎)
萬能的git啊,help me!
功夫不負有心人,找到了解決問題的方法,其實就是 git rm
的命令列引數。
git rm
命令引數
-n --dry-run
Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.
-r
Allow recursive removal when a leading directory name is given.
--cached
Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.
解決方法
git rm -r -n --cached "bin/" //-n:加上這個引數,執行命令時,是不會刪除任何檔案,而是展示此命令要刪除的檔案列表預覽。
git rm -r --cached "bin/" //最終執行命令.
git commit -m" remove bin folder all file out of control" //提交
git push origin master //提交到遠端伺服器
此時 git status
看到 bin/目錄狀態變為 untracked
可以修改 .gitignore
bin/
並提交 .gitignore
檔案到遠端伺服器,這樣就可以不對bin目錄進行版本管理了。
以後需要的時候,只需要註釋 .gitignore
裡 #bin/
內容,重新執行 git
bin/
,即可重新納入版本管理。