Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I retrieve commits in "overwritten" branch in Git?

Tags:

git

branch

Background

I'm working with just one branch - master.

        3---------2---------
                            |
6-------5---------4---------1----------

I made commits 1-3, then realised I wanted to work from commit 1 for the next section of work. I checked out commit 1, then made commits 4-6. Ooops. Commit 3 contains some important information I need.

The Problem

When I do a git log or view All Branches in GitX, all I see is this:

6-------5---------4---------1----------

How can I merge bits of commits 3 back to commit 6? (Is this called HEAD?)

Have I lost commits 2 and 3?

I know it was my fault for not making a new branch, but does that mean those commits are lost?

I'm still a Git newbie (despite using it for about 6 months) and still find it really confusing, so please be gentle!

like image 531
John Gallagher Avatar asked Dec 18 '09 13:12

John Gallagher


1 Answers

You have not lost the commits. They are available in the reflog.

Run git reflog and find the commits.

If you want the result to look like 6-5-4-3-2-1, checkout 6 and rebase it on 3.

like image 84
Alex Brasetvik Avatar answered Nov 15 '22 06:11

Alex Brasetvik