Discarding Local Changes in a File
1. Checking out the main branch
git switch main
2. Change index.html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h2>Welcome</h2>
<p>This is the paragraph i want to revert !!!</p>
</body>
</html>
3. Check the status
git status
4.Discarding the changes in the working directory
git checkout index.html
git status
cat index.html
How to Discard Changes in Git?
In Git, “discard changes” refers to reverting modifications made to files in your working directory back to their state in the last commit, effectively disregarding any changes you’ve made since then. This action can be useful if you’ve made changes that you no longer want to keep or if you want to start over from the last committed state.
Table of Content
- Steps to Setup Github
- Discarding Local Changes in a File
- Discarding All Local Changes
- Saving Changes on the Stash