Git "forget" already tracked files

Scenario: A project is initialized, add a .gitignore file with content .idea. But unfortunately the folder idea is already in the git repo, generate the .gitignore file later will not remove the folder from the repo.

Solutions:

1.

Make sure the working space is clean

$ git rm -r --cached .idea/
rm '.idea/.gitignore'
rm '.idea/UpdateTvtsPkg.iml'
rm '.idea/dictionaries'
rm '.idea/inspectionProfiles/Project_Default.xml'
rm '.idea/inspectionProfiles/profiles_settings.xml'
rm '.idea/misc.xml'
rm '.idea/modules.xml'
rm '.idea/vcs.xml'
git add -u
git commit -m "Update git ignored files/folders"
git push

2.

Make sure the working space is clean

# Remove all tracked files, including wanted and unwanted
git rm -r --cached .
# Add all the files/folders expect those in .gitignore
git add .
git commit -m "Update git ignored files/folders"
git push

.gitignore will prevent untracked files from being added (without an add -f) to the set of files tracked by Git. However, Git will continue to track any files that are already being tracked.

WARNING: While this will not remove the physical file from your local machine, it will remove the files from other developers' machines on their next git pull.

你可能感兴趣的:(Git "forget" already tracked files)