gitignore just doesn't work. I can't get it to ignore .DS_Store & .gitignore files

前端 未结 10 1919
一整个雨季
一整个雨季 2021-02-07 20:12

I have .gitignored .DS_Store and .gitignore files. But still see them in the \"git status\".

Can someone explain to me how I can m

相关标签:
10条回答
  • 2021-02-07 20:28

    This is building off of Jakub Jirutka's response. I was a little confused upon first glance, but I tried it and it worked. Here is his answer stated - hopefully - more clearly.

    His answer put simply: store unwanted files in .git/info/exclude (which is inside every git repository). Put each on a new line.

    The .gitignore file is useful to help ignore files and directories that you know are or will be generated but are unwanted. The fact that you can git add .gitignore and then commit that and push it is really useful. When you clone this repository on another computer, for example, all of the files that should be ignored (after a ./configure; make; sudo make install;, for example, usually generates example files and a lot of other links) will be ignored (if they are in the .gitignore.

    However, sometimes, one is not sure whether a file is wanted in the repository or wants the file to just exist outside of git control as if it were in a non-git-controlled directory. This can be done by adding this to the exclude file inside of the exclude file inside the .git/info directory.

    Every git repository has a .git folder. To completely exclude a file or directory, go to the good ole terminal, cd to the root of the repository (i.e. cd src/best_repo_eva). Then you will see a .git/. Then, cd .git/info/. There will probably only be one file there called exclude. Use your favorite editor (just kidding; you may only use butterflies' wings to focus cosmic rays in the upper atmosphere to flip the correct bits in your drive platter ;) to edit the exclude such that it contains the files you want to exclude on new lines.

    Easier solution: You have two files you want excluded: tmp1 and ignoreadf

    Go to terminal and...

    • cd src/best_repo_eva
    • echo -e "tmptab\n igntab" >> .git/info/exclude

    The tabs, obviously, only work if your terminal supports it. Note the -e (supports backslash escapes) and the \n (which is emphasized with a space) between the the two files.

    Storing a lot of files with a similar ending, could be as easy as cd src/best_repo_eva then echo -e $(ls -1 | grep "tmp") >> .git/info/exclude (that's ls -ONE not ls -L - note that ls -a -1 doesn't work, unfortunately). That would store all files that contain the sequence "tmp" into the exclude file.

    0 讨论(0)
  • 2021-02-07 20:35

    Why you’re ignoring .gitignore? This doesn’t make a sense. If you want to ignore some files just locally (i.e. don’t track and publish this setting to the remote repository), then use .git/info/exclude instead. Just add .DS_Store to it, that’s all.

    0 讨论(0)
  • 2021-02-07 20:41

    Add the lines

     **/.DS_Store
     **/.gitignore
    
    0 讨论(0)
  • 2021-02-07 20:42
    1. You shouldn't ignore your .gitignore. I don't think the ignore feature works when you don't have it in your repository. I'm not sure though.
    2. Files that are already tracked won't be ignored, even if you add them to .gitignore. If you want them to be ignored after they've been added to the repository already, you have to remove them with git rm filename first.
    0 讨论(0)
提交回复
热议问题