Search code examples
gitgitignore

Adding several items to .gitignore


I have a project with a layout like this:

folder_a
    folder_b
       file1.html
       file2.html
    folder_c
       file3.html
       file4.html
    folder_d
    .gitignore

Now, my goal is to include file3.html and the entire contents of folder_a/folder_b to .gitignore. To achieve this, I have written the following in .gitignore:

folder_b/
folder_c/file3.html

This seems elementary, and yet it doesn't work for me. The data still gets updated. What am I doing wrong? I've read the doc, and now it seems like I should write the full path, is it true? I am stuck.


Solution

  • The purpose of .gitignore is to exclude files from version control, not to prevent changes to files that are already in version control. Make sure that the files that you want to exclude are not in version control. You can do that without deleting the files on disk with commands like this:

    git rm --cached folder_c/file3.html
    

    And then commit the result.

    Edit: It seems that OP wants to ignore new changes to files that are in version control. For that case there is a relevant answer on this question: How do I stop Git from tracking any changes to a file from this commit forward?