Skip to content

Instantly share code, notes, and snippets.

@nealfennimore
Created November 14, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealfennimore/55dc8bfaa6202fc1d4f303bdbf88d9c5 to your computer and use it in GitHub Desktop.
Save nealfennimore/55dc8bfaa6202fc1d4f303bdbf88d9c5 to your computer and use it in GitHub Desktop.
Git checkout to previous working commit
# We're currently on `non-working` branch, and we've identified a previous working commit of `abcdef123456`.
# We want to go back to commit `abcdef123456`, and then start work anew from there
# First checkout to the working commit `abcdef123456`
git checkout abcdef123456
# You'll be in a temporary staging area now. If we want to make changes now, we'll need to copy the current commit
# into a new branch.
git checkout -b previous-working-branch
# Now if you check git log, you should see the working commit as `abcdef123456`
git log
# Outputs:
# commit abcdef123456<rest of hash> (HEAD -> previous-working-branch)
# Author: Whomever <email@email.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment