threads / discuss / 23478

Lost a week?

Subject: Lost a week?

## tl;dr

5 messages between Apr 15, 2010 and Apr 15, 2010.

replies: 4people: 4as markdown or json

Daniel Grace· Apr 15, 2010, 13:57 UTC · lore

Appologies for not having more information. I usually use git as if it's just SVN with non-network checkins.

A few days ago, I pushed my git repository to github:

127 git remote add github git@github.com:negativeview/Wherespresso.git [Note, this is a private repo] 128 git push github master

I then went about doing real-world business. I noticed at some point that when I did a `git status` it said that no branches were checked out. I don't remember doing anything between pushing to github and this state. If I did a git branch it shows something like * (no branch) then below that, master. I shrugged it off and did what I expected to fix that odd issue:

515 git branch 516 git checkout master

Now, the next day, I noticed that I have no git history between the 6th and something I did soon after the git checkout master:

$ git log | grep Date | head -n 5
Date:   Wed Apr 14 14:43:58 2010 -0500
Date:   Tue Apr 6 00:42:20 2010 -0500
Date:   Mon Apr 5 23:57:54 2010 -0500
Date:   Mon Apr 5 07:01:26 2010 -0500
Date:   Mon Apr 5 06:17:18 2010 -0500

github shows the same. I KNOW that there were commits (representing a good bit of work) in that time. I'm sure that it's *somewhere* but I'm at a complete loss as to where it is. gitk shows no side branches (nor does git branch). I don't use branches really, as much as I know that I should.

Daniel http://www.doomstick.com

Michael J Gruber· Apr 15, 2010, 14:11 UTC · re: Daniel Grace · lore

Re: Lost a week?

Daniel Grace venit, vidit, dixit 15.04.2010 15:57:
Show 38 quoted lines
> Appologies for not having more information. I usually use git as if
> it's just SVN with non-network checkins.
> 
> A few days ago, I pushed my git repository to github:
> 
> 127  git remote add github
> git@github.com:negativeview/Wherespresso.git [Note, this is a private
> repo]
> 128  git push github master
> 
> I then went about doing real-world business. I noticed at some point
> that when I did a `git status` it said that no branches were checked
> out. I don't remember doing anything between pushing to github and
> this state. If I did a git branch it shows something like * (no
> branch) then below that, master. I shrugged it off and did what I
> expected to fix that odd issue:
> 
> 515  git branch
> 516  git checkout master
> 
> Now, the next day, I noticed that I have no git history between the
> 6th and something I did soon after the git checkout master:
> 
> $ git log | grep Date | head -n 5
> Date:   Wed Apr 14 14:43:58 2010 -0500
> Date:   Tue Apr 6 00:42:20 2010 -0500
> Date:   Mon Apr 5 23:57:54 2010 -0500
> Date:   Mon Apr 5 07:01:26 2010 -0500
> Date:   Mon Apr 5 06:17:18 2010 -0500
> 
> github shows the same. I KNOW that there were commits (representing a
> good bit of work) in that time. I'm sure that it's *somewhere* but I'm
> at a complete loss as to where it is. gitk shows no side branches (nor
> does git branch). I don't use branches really, as much as I know that
> I should.
> 
> Daniel
> http://www.doomstick.com
Backup now.

Most probably, you've made those commits on a detached HEAD. May you have checked out a remote branch, or a specific commit, before you went about your business on or after 6th?

git reflog (or git log -g) will be able to show you the history of your HEAD before you lost it ;)

Then you can tag those commits or 'checkout -b safehaven nameofthetopcommit' to get a branch with those commits. Now they are safe from being pruned during garbage collection.

Michael
Thomas Rast· Apr 15, 2010, 14:16 UTC · re: Daniel Grace · lore

Re: Lost a week?

Daniel Grace wrote:
> I then went about doing real-world business. I noticed at some point
> that when I did a `git status` it said that no branches were checked
> out.
Read this: http://sitaramc.github.com/concepts/detached-head.html

(I don't want to sound dismissive, there's just not much not covered in that article :-)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Matthieu Moy· Apr 15, 2010, 14:16 UTC · re: Daniel Grace · lore

Re: Lost a week?

Daniel Grace <negativeview@gmail.com> writes:
Show 5 quoted lines
> github shows the same. I KNOW that there were commits (representing a
> good bit of work) in that time. I'm sure that it's *somewhere* but I'm
> at a complete loss as to where it is. gitk shows no side branches (nor
> does git branch). I don't use branches really, as much as I know that
> I should.

I guess you've been on a detached HEAD for some time. Recent version of Git warn you this way when you enter in this state:

,----
| Note: checking out 'HEAD^'.
| 
| You are in 'detached HEAD' state. You can look around, make experimental
| changes and commit them, and you can discard any commits you make in this
| state without impacting any branches by performing another checkout.
| 
| If you want to create a new branch to retain commits you create, you may
| do so (now or later) by using -b with the checkout command again. Example:
| 
|   git checkout -b new_branch_name
| 
| HEAD is now at a8e7ba9... foo
`----

Now, your changes are probably not lost forever: they're not reachable from a branch, but still there (but don't play with "git gc" until you're sure you've recovered all of it...). "git reflog" should give you the sha1 of the commit you're looking for (if you didn't really mess up everything, you really look for just one commit, which is the tip of the sequence of commits you did while on a detached HEAD, that is, the one just before you did "git checkout master".

Then, do

git branch tmp <the-sha1-you-found> (possibly run "gitk --all" to understand, here) git merge tmp

to create a branch named tmp containing your commits, and merge it into your current branch. Naming the branch isn't strictly necessary, but will help in case you do anything wrong trying to merge.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Daniel Grace· Apr 15, 2010, 14:29 UTC · re: Matthieu Moy · lore

Re: Lost a week?

Thanks everyone! I had heard the phrase "detached head" before, but didn't really understand what it is. I'm glad to note that all my commits were there. I wasn't really worried, I knew that git had stored it dutifully away SOMEWHERE.

I have that page bookmarked now Thomas. Unfortunately I have customer work to do now that I am not missing work, but I promise to read and understand it fully as soon as I'm done with that.

Daniel http://www.doomstick.com

On Thu, Apr 15, 2010 at 9:16 AM, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:

Show 48 quoted lines
> Daniel Grace <negativeview@gmail.com> writes:
>
>> github shows the same. I KNOW that there were commits (representing a
>> good bit of work) in that time. I'm sure that it's *somewhere* but I'm
>> at a complete loss as to where it is. gitk shows no side branches (nor
>> does git branch). I don't use branches really, as much as I know that
>> I should.
>
> I guess you've been on a detached HEAD for some time. Recent version
> of Git warn you this way when you enter in this state:
>
> ,----
> | Note: checking out 'HEAD^'.
> |
> | You are in 'detached HEAD' state. You can look around, make experimental
> | changes and commit them, and you can discard any commits you make in this
> | state without impacting any branches by performing another checkout.
> |
> | If you want to create a new branch to retain commits you create, you may
> | do so (now or later) by using -b with the checkout command again. Example:
> |
> |   git checkout -b new_branch_name
> |
> | HEAD is now at a8e7ba9... foo
> `----
>
> Now, your changes are probably not lost forever: they're not reachable
> from a branch, but still there (but don't play with "git gc" until
> you're sure you've recovered all of it...). "git reflog" should give
> you the sha1 of the commit you're looking for (if you didn't really
> mess up everything, you really look for just one commit, which is the
> tip of the sequence of commits you did while on a detached HEAD, that
> is, the one just before you did "git checkout master".
>
> Then, do
>
> git branch tmp <the-sha1-you-found>
> (possibly run "gitk --all" to understand, here)
> git merge tmp
>
> to create a branch named tmp containing your commits, and merge it
> into your current branch. Naming the branch isn't strictly necessary,
> but will help in case you do anything wrong trying to merge.
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>

← back to recent threads