This article will demonstrate:
How to Discard Tracked and Untracked Modified Files?
To discard all the tracked and untracked modified files, the “git reset –hard” command is used. Follow the provided steps, to do so.
Step 1: View Repository Status
First, utilize the “git status” command and view the repository’s current status:
The above output indicates that the repository contains some tracked and untracked modified files.
Step 2: Discard All Modified Files
To discard all the tracked and untracked modified files, run the below-listed command:
The output shows that all modified files have been discarded.
Step 3: Verify Changes
Lastly, view the Git status again to ensure changes:
The above output shows that Git status is clear now which means that the modified files’ modifications have been discarded.
How to Discard Only Untracked Modified Files?
To discard untracked modified files, utilize the “git checkout .” command. For a better understanding, check out the following steps:
Step 1: Check Git Status
First, view the repository’s current status:
The above output shows two untracked modified files in the repository.
Step 2: Discard Untracked Modified Files
Then, utilize the following command to discard untracked modified files:
The output confirms that untracked modified files have been discarded.
Step 3: Verification
To verify whether the modified files have been discarded or not, view the repository status:
The above output indicates that the untracked modified files’ changes have been discarded:
That was all about discarding modified files in Git.
Conclusion
To discard all the tracked and untracked modified files, the “git reset –hard” command is used. To discard only untracked modified files, utilize the “git checkout .” command. To verify whether the modified files have been discarded or not, view the repository status via the “git status” command.
This article has demonstrated the methods to discard modified files in Git.