Remove Untracked Files and Directories
To remove untracked files and directories, use the following commands:
Untracked Files:
git clean -f
Untracked Directories:
git clean -fd
To see what will be removed before actually deleting the files, use:
git clean -n
Example: To demonstrate removing untracked files and directories in git.
Note: Here we can see that using git clean -n is informing user what would it remove then following git clean -f actually removed the untracked file dummy.py.
How to Discard all Changes in Git?
Git is a popular version control tool that remembers all the changes made to a set of files over time. This is especially useful for software development, where multiple people might be working on the same code.
Table of Content
- What are the Changes in Git?
- State of git changes
- 1. Discard Uncommitted Changes in Tracked Files
- 2. Remove Untracked Files and Directories
- 3. Discard staged changes in Git
- FAQs.