IAC - Version Control
GITHUB
GITHUB
  • Background
  • Setting up GitHub
  • Windows
    • Working with a cloned repo
    • Populating a repo from local files
    • Integrate VSCode
  • Linux
    • Using SSH
    • GH Command Line
  • The Basics
    • Forks
    • Logs
    • Undoing Local Changes
  • Larger Projects
    • Setting up a repo
    • Creating my Branch Architecture Locally
    • Creating a Feature Branch
    • Creating my Branch Architecture on GitHub
    • Merging the changes from GitHub on my local machine
    • Merging the changes from my local machine to GitHub
    • Sync the branches in GitHub
  • Finally
Powered by GitBook
On this page
  • Undo before Staging
  • Undo after Staging
  • Undo after Commit
  1. The Basics

Undoing Local Changes

PreviousLogsNextLarger Projects

Undo before Staging

My starting point is to check the current status, both locally and in VSCode.

Now I’m making a small change in jor.txt and saving but I have not staged or committed.

Imagine I have broken something, and I want to revert to the last committed version. If I use the command git checkout filename I can revert to the previous version. I could also use git restore filename.

Undo after Staging

I have changed the same file again and this time, I have staged the change.

You may notice, each time git tells me my options! In this case, I will restore the staged file.

Now I can either remodify or restore from the last commit.

Undo after Commit

This time I will stage and commit all using VSCode. I am using the message “Update at 14:46”.

First, I need to identify the version I want. As you can see, my messages are very unhelpful, that is a lesson! I want to revert to a previous saved version.

To go back to that version, I can also use git checkout hash with the hash of the version I want to restore.

I can then commit this and push it to GitHub.

And finally, to check it really has updated....