Reputation: 32721
I added a .gitignore
file after git add .
. I'd like to know if I can proceed to git commit and push it and git will ignore the files.
If not how should I delete the files which I git add
ed.
Where does .gitignore
affect? git add
, git commit
or git push
?
Upvotes: 2
Views: 529
Reputation: 6485
There are a few ways to go about this. Here's one way.
Firstly let's undo that git add .
for the file you don't want git to track. Run this git reset HEAD <file to remove>
. Now, add the .gitignore file with git add .gitignore
and git commit -m 'your comment'
. Now if you do git status
you should find that git is not indicating that your file is untracked.
I am assuming your .gitignore file already contains things to ignore
As for "Where does .gitignore affect?"
When you update your .gitignore file it will make it so that git will not see/find files and directories that you're trying to ignore. So if you were to do a git status
you would not see those files or directories. If you did a git add .
those files and directories would not be added since git does not see them. However, if git is already tracking the file or directory and you then update the .gitignore you will find that it doesn't just ignore those already tracked files. You will have tell git to untrack them.
Upvotes: 1
Reputation: 6629
you can read the article it will clear your thoughts about .gitignone and FYI you can put those file entries into .gitignore those you wants to don't add into consideration on adding and commiting your files.
Upvotes: 0
Reputation: 1326982
If your gitignore is for file you already added, you need also to:
git rm --cached thosefiles
(remove them from the index, not from the disk)git add -A
(will record those deletions plus your gitignore=git commit
and pushUpvotes: 2