JoiWiki » Developer » Applications » Git » Git Commands » Reverting Changes Reverting Changes

Reverting Changes

Reverting changes in Git

This can be a bit of a pain but it needn't be! Things that I've missed can be found here. For regularly used commands feel free to peruse below:


Reverting to last local commit (reset everything)

So you've checked out a branch, had a play around with it but you don't want to keep the changes - no worries at all!

# Revert all files back to the state they most previously were
git reset --hard

# Now get rid of all of the files made since then
git clean -fd

Perfect, now you're back where you were when you checked the branch out! (assuming you didn't have anything else in that folder, otherwise you might well have just deleted it..)


Reverting changes to a single unstaged file:

So you're working on a branch and you've accidentally changed a file that you've no intention of updating and it's showing as awaiting staging. Here's how to pull back the original version of the file:

# Re-grab the specific file we didn't want to change from the last commit
git checkout -- [Filename]


Rolling back a commit on a repo


git clone <repo_url>  #clone your azure git repo to local
git checkout <branch>

git reset --hard <commithash> #revert back to a the previous commit
git push --force  #push to remote server


Created by JBaker. Last Modification: Wednesday May 29, 2024 11:25:38 BST by JBaker.