Git - Tutorial remove untracked files
Note: This post is over 11 years old. The information may be outdated.
If you have a bunch of untracked files and want to remove them all in one go then just do this:
$ git clean -f
Useful Options
Dry run - See what would be removed without actually deleting:
$ git clean -n
Remove untracked directories - Include directories in cleanup:
$ git clean -fd
Interactive mode - Choose which files to remove:
$ git clean -i
Force with directories - Remove both files and directories:
$ git clean -ffd
Important Notes
- Untracked files are files that Git hasn't tracked yet (not in
.gitignore, not staged, not committed) - Warning:
git cleanis destructive and cannot be undone. Always use-n(dry run) first to verify what will be deleted - Use
git cleanto clean up build artifacts, node_modules, logs, and other temporary files not tracked by Git
Related Posts
Git - 19 Tips For Everyday Git Use
I’ve been using git full time for the past 4 years, and I wanted to share the most practical tips that I’ve learned along the way. Hopefully, it will be useful to somebody out there
Git rebase, gộp commits bằng rebase
Trong dự án, code của bạn luôn có sự thay đổi, sau khi push 1 đống commit lên github. Một ngày kia ông Leader kêu lại: "Ê mày, sửa chỗ này, sửa chỗ kia, code không đúng chuẩn rồi, bla bla ...". Thế là phải hồi hì hục cải tiến code, coding style cho "chuẩn".
Git - Cách xóa nhanh tất cả các branch cũ đã merge vào branch master
Nếu bạn có rất nhiều branch trên repo, mỗi branch phát triển 1 chức năng của dự án. Trong số chúng có nhiều branch đã hoàn thành, và đã được merge vào branch chính (master) chẳng hạn, mình gọi các branch này là branch cũ.
Git - Cách xem nội dung 1 file ở branch khác
Nếu bạn đang ở 1 nhánh, và bạn muốn xem nội dung của 1 file nằm ở trên nhánh khác mà không cần phải checkout.