using gitignore to ignore (but not delete) files

后端 未结 5 1336
心在旅途
心在旅途 2020-12-12 11:35

I have a tmp directory in my git repo I\'d like to still exist, but be ignored. I added it to .gitignore, but git status still tells me about chan

5条回答
  •  星月不相逢
    2020-12-12 11:55

    Put a / at the end of the directory name in your .gitignore file, i.e.

    tmp/
    

    If have tracked files inside that directory, you need to tell git to forget about them first (before you add the dir to the ignore list). Assuming you have nothing vital in there (i.e. that you can scratch it):

    git rm -rf ./tmp/
    git commit -m "untrack tmp dir"
    mkdir tmp
    echo tmp/ >> .gitignore
    git add .gitignore ; git commit -m "add tmp/ to ignore list"
    

    New files in that directory will not be tracked.

    The --cached option to git rm only works on the index (pending changes more or less). It has no effect on the working tree or the status of what has been tracked or not.

提交回复
热议问题