git: How to ignore all present untracked files?

前端 未结 8 1635
北恋
北恋 2020-12-22 14:57

Is there a handy way to ignore all untracked files and folders in a git repository?
(I know about the .gitignore.)

So git status would

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-22 15:16

    I came here trying to solve a slightly different problem. Maybe this will be useful to someone else:

    I create a new branch feature-a. as part of this branch I create new directories and need to modify .gitignore to suppress some of them. This happens a lot when adding new tools to a project that create various cache folders. .serverless, .terraform, etc.

    Before I'm ready to merge that back to master I have something else come up, so I checkout master again, but now git status picks up those suppressed folders again, since the .gitignore hasn't been merged yet.

    The answer here is actually simple, though I had to find this blog to figure it out:

    Just checkout the .gitignore file from feature-a branch

    git checkout feature-a -- feature-a/.gitignore
    git add .
    git commit -m "update .gitignore from feature-a branch"
    

提交回复
热议问题