I committed my changes locally but I haven't pushed, how do I revert or undo with Git?
Answer:
If you have committed your changes locally but you haven't pushed the changes to your remote repository, here are some steps to revert or undo your changes.
-
Check the changes in your repo
wvs git status
-
If changes were committed locally, they would not show up as a list of changed files, and you would get an output similar to this:
D:\WVSprojects\LyraStarterGame52>wvs git status
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
- Once it's been confirmed that the files were committed, you can do the following:
To undo changes to an individual file, move the file out of your local commit.
wvs git restore --staged <file>
Once you move it out, you can proceed and undo individual files.
wvs git checkout --<file>
- If you want to undo or revert All your Files in your commit, you can run the following:
wvs git reset --hard
Note: Step 4 will undo all your files in the commit, so do not use this option if you want to pick out specific files to undo.