Home  >  Q&A  >  body text

git 忽略文件

我刚开始接触git 然后想忽略文件 但是出现了一些我不知道怎么解决的问题
比如,我想忽略html文件
我使用

cat .gitignore
vim .gitignore

然后在.gitignore文件的编辑模式下,写下

#忽略以html结尾的文件
*.html

保存退出

我在看git status的时候,hmtl文件确实是没有了,但确出现了

我需要提交.gitignore文件.是不是我忽略文件的方式有问题

淡淡烟草味淡淡烟草味2727 days ago561

reply all(6)I'll reply

  • 大家讲道理

    大家讲道理2017-05-02 09:35:19

    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:

    modified: .gitignore 红色标记状态,等待加入add命令暂存下一步提交
    

    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...'

    reply
    0
  • 黄舟

    黄舟2017-05-02 09:35:19

    Modified.gitignore, it needs to be submitted normally, and there is no problem

    reply
    0
  • 高洛峰

    高洛峰2017-05-02 09:35:19

    If gitignore does not appear to be modified, then the file you used to ignore the file has been ignored. Isn’t it very messy?

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-02 09:35:19

    Did you not commit? . . .gitignore generally requires commit

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-02 09:35:19

    If you modify it, it counts as a modification and you have to commit it

    reply
    0
  • PHP中文网

    PHP中文网2017-05-02 09:35:19

    .gitignore Submit

    reply
    0
  • Cancelreply