Skip to content

Instantly share code, notes, and snippets.

@alantsai
Last active January 11, 2018 19:25
Show Gist options
  • Save alantsai/7c9667567543f981cdcc027ae9ddb2e9 to your computer and use it in GitHub Desktop.
Save alantsai/7c9667567543f981cdcc027ae9ddb2e9 to your computer and use it in GitHub Desktop.
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment