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
-
Produce the
.gitignore
file first and place in the root of git project -
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 .
- 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 .
- commit change - all path in .gitignore will be deleted
git commit -m "Add gitignore and remove ignore track file"