问题
I want to stop tracking certain files in Git that I've added to the .gitignore
file.
I used git rm --cached
(and also tried git rm -r --cached .
) but after running git add .
, a git commit --dry-run
tells me the files in my gitignore are "to be committed".
The contents of the .gitignore
file are:
/source/backup/*
/site/index.php
/site/userscript.user.js
What's wrong with this gitignore?
Things were working just fine when the only line was source/backup/*
. As soon as I added the second line, the source/backup/*
files are getting committed as well.
回答1:
Clear out your index.
git reset
Stop tracking files in your backup folder.
git rm --cached source/backup/
Commit this change by itself.
git commit -m "Removing backup folder from git."
Proceed normally. Ignored files should not accidentally slip in at this point provided your ignore file is setup properly. I'd recommend preceding it with a slash (assuming that folder exists in the root of your repository).
#.gitignore
/source/backup/
/site/index.php
Open up YouTube. Master git. http://youtu.be/ZDR433b0HJY
来源:https://stackoverflow.com/questions/15774606/git-add-does-add-files-listed-in-gitignore