Mastering Git - Part 10: Many Faces of Undo | Ray Wenderlich

One of the common questions associated with git is "how can I get out of this mess?". In this video you'll learn about the different "undo" commands that git provides—what they are and when to use them.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4289-mastering-git/lessons/10

Why do you suggest creating a new temp branch to recover a deleted commit, as opposed to just resetting head to HEAD@{1}.
For example,

  1. git reset --hard HEAD^1 -oops lost my latest change
  2. git reset --hard HEAD@{1} - change is back.

Is there a case where doing git checkout , git branch temp-branch, git checkout master, git reset --hard HEAD@{4} would produce different results?

Hiya @fecteauj

I showed the route with checking out a temporary branch to give a better flavour of what was going on, and how the reflog works. There is absolutely no reason why you can’t (and shouldn’t) take the approach you mentioned.

It’s been a while, but if I remember correctly, knowing how to do this is helpful for the challenge? Or maybe a dreamt it.

sam

Ok. I figured it was something like that. I just wanted to make to sure I wasn’t missing something obvious. I’m fairly new to git and still getting used to working with it.

It definitely was needed for the challenge to recover a branch so it’s good to know how to get that done.

This topic was automatically closed after 166 days. New replies are no longer allowed.