Discard Uncommitted Changes in Tracked Files
To discard changes in tracked files (both staged and unstaged), use the following command:
git reset --hard
This will reset the working directory and the staging area to match the most recent commit. Note that this will discard all local changes that have not been committed.
Example: To demonstrate discarding uncommited changes in the tracked files in git.
Note: Here after using git reset –hard the deleted files(example.py,dummy2.py) is back as these changes were uncommitted.
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.
Contact Us