Git In-depth Git In-depth

Recover Lost Work

Learning Paths:
Check out a free preview of the full Git In-depth course:
The "Recover Lost Work" Lesson is part of the full, Git In-depth course featured in this preview video. Here's what you'd learn in this lesson:

Nina discusses techniques to recover lost work with git and GitHub.

Get Unlimited Access Now

Transcript from the "Recover Lost Work" Lesson

>> Nina Zakharenko: How can we possibly recover last work? Well, remember about original HEAD, that I had mentioned before. That's the commit that HEAD was pointing to before we did a reset or a merge. If things really get screwed up, it might be time to check for copies of your repository.

[00:00:17] Maybe, if you look on GitHub, maybe one of your coworkers has a copy that you can grab. How would we use original head to undo a merge? In this case we could do get result//merge, using the merge flag is going uncommitted charges. So, if you added some things using that flag won't blow them away.

[00:00:46] So by resetting, we're just moving HEAD back, and that's it.
>> Nina Zakharenko: If you end up with one of these dangling commits, and you need to get them back. By default, you keep commits around for maybe two or three weeks. If you need to go back in time and find a commit that's no longer referenced, you can take a look in the rough log.

[00:01:10] The syntax of rough log is a little different, so HEAD@{2} means the value of head as it was two moves ago. If you're looking for a dangling commit, you mess up a rebiz, you committed some changes on a detached head using git reflog is how you're going to get them back.