How to remove local (untracked) files from the current Git working tree

前端 未结 30 2122
死守一世寂寞
死守一世寂寞 2020-11-22 00:07

How do you delete untracked local files from your current working tree?

30条回答
  •  爱一瞬间的悲伤
    2020-11-22 00:48

    OK, deleting unwanted untracked files and folders are easy using git in command line, just do it like this:

    git clean -fd
    

    Double check before doing it as it will delete the files and folders without making any history...

    Also in this case, -f stands for force and -d stands for directory...

    So, if you want to delete files only, you can use -f only:

    git clean -f
    

    If you want to delete(directories) and files, you can delete only untracked directories and files like this:

    git clean -fd
    

    Also, you can use -x flag for including the files which are ignored by git. This would be helpful if you want to delete everything.

    And adding -i flag, makes git asking you for permission for deleting files one by one on the go.

    If you not sure and want to check things first, add -n flag.

    Use -q if you don't want to see any report after successful deletion.

    I also create the image below to make it more memorable, especially I have seen many people confuse -f for cleaning folder sometimes or mix it up somehow!


提交回复
热议问题