I just started to use git and I want to ignore files, but there are some problems that I don’t know how to solve
For example, I want to ignore html files
I use
cat .gitignore
vim .gitignore
Then in the edit mode of the .gitignore file, write
#忽略以html结尾的文件
*.html
Save and exit
When I looked at git status, the hmtl file was indeed gone, but it did appear
I need to submit the .gitignore file. Is there something wrong with the way I ignore the file?
1. There is nothing wrong with the way you ignore files
2. .gitignore files can work normally without submitting them
3. Git will only ignore untracked files in the .git library based on .gitignore
If your "new file.html" can be ignored and the "old file.html" that has been submitted is re-modified, then Git will not ignore the latter.
Method:
1. Execute git rm --cached old file.html
2. Execute git commit old file.html -m 'Comment...'
Explanation:
1. Delete the tracked files from the .git library without deleting them locally (if you want to delete them locally, do not add git before the rm command)
2. Submit, and then the files are removed from the .git library. Really deleted
After that, "old file.html" will no longer be tracked
---------------Separating line-----------------
Because the .gitignore file has been submitted, Git has tracked it, and you have modified the .gitignore file again
Then when you check the status with git status, of course it is:
Method 1, undo modifications:
Execute git checkout -- ".gitignore"
Method 2: Submit the modification to the .git library and let Git track it:
Execute git add .gitignore
Execute git commit .gitignore -m 'Comment...'
Modified
.gitignore
, it needs to be submitted normally, and there is no problemIf gitignore does not appear to be modified, then the file you used to ignore the file has been ignored. Isn’t it very messy?
Did you not commit? . . .gitignore generally requires commit
If you modify it, it counts as a modification and you have to commit it
.gitignore Submit