Discard Untracked Changes
You are working on a project using Git and have made some changes to your working directory. However, you realize that you don't need these changes and want to discard them. You want to discard all untracked changes to the current branch.
To complete this lab, you will use the Git repository named https://github.com/labex-labs/git-playground
. Follow these steps:
- Navigate to the repository directory:
cd git-playground
- Check the status of your working directory:
git status
You should see the following output:
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
new-file.txt
nothing added to commit but untracked files present (use "git add" to track)
- Discard all untracked changes to the current branch:
git clean -f -d
- Check the status of your working directory again:
git status
You should see the following output:
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
The git clean -f -d
command has discarded all untracked changes to the current branch.