AlanTsai
5/11/2016 - 1:33 AM

remove all track file which are ignored in the .gitignore - 把git裡面屬於.gitignore檔案被加入版控的檔案從版控刪掉 #git

remove all track file which are ignored in the .gitignore - 把git裡面屬於.gitignore檔案被加入版控的檔案從版控刪掉 #git

Sometimes some files are accedntily added into the source control, which later relaized caused by not include a project level .gitignore

Below command provide way to remove all track files which should be ignored

  1. Produce the .gitignore file first and place in the root of git project

  2. Remove all files (-r for recurse, . mean from current directory) from git
    but leave the physical file untouch (indicate by the --cache option)

git rm -r --cached .
  1. since everything is removed from git but not the physical file, do a add
    will add all local file to stage. This time, take into account of .gitignore rule
git add .
  1. commit change - all path in .gitignore will be deleted
git commit -m "Add gitignore and remove ignore track file"