git 忽略已加入到版本库的文件

张映 发表于 2018-08-17

分类目录: 技术其他

标签:, ,

.gitignore可以忽略没有加入版本库中的文件或者文件夹,但是已经加入到版本库的,.gitignore是无用的。

1,git rm 可以将文件和文件夹从版本库中删除,但是本地也会删除。

2,git rm --cache 可以将文件和文件夹从版本库中删除,但是本地会保留

  1. MacBook-Pro:test zhangying$ git rm --cache aaa  //删除,本地保留  
  2. rm 'aaa'  
  3.   
  4. MacBook-Pro:test zhangying$ git commit -m "test" //提交到本地库  
  5. [master 07983fc] test  
  6.  1 file changed, 4 deletions(-)  
  7.  delete mode 100644 aaa  
  8.   
  9. MacBook-Pro:test zhangying$ git push  //提交远程库  
  10. Counting objects: 2, done.  
  11. Delta compression using up to 4 threads.  
  12. Compressing objects: 100% (2/2), done.  
  13. Writing objects: 100% (2/2), 229 bytes | 0 bytes/s, done.  
  14. Total 2 (delta 1), reused 0 (delta 0)  
  15. To 192.168.0.5:root/test.git  
  16.  afd326d..07983fc master -> master  
  17.   
  18. MacBook-Pro:test zhangying$ ls   //查看一下,本地文件存大  
  19. 1 2 aaa bbb hao.txt index.php mas test1  
  20.   
  21. MacBook-Pro:test zhangying$ vim aaa //修改一下  
  22.   
  23. MacBook-Pro:test zhangying$ git status  //查看一下状态,没变化,已忽略  
  24. On branch master  
  25. Your branch is up-to-date with 'test/master'.  
  26. nothing to commit, working tree clean  

 



转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/other/1951.html