threads / bug / 34603

Re: Bug: Pulling remotes into an empty repo deletes the index

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index

## tl;dr

7 messages between Aug 3, 2013 and Aug 10, 2013.

replies: 6people: 4as markdown or json

Adam A· Aug 3, 2013, 12:01 UTC · lore

Hello, the project readme on github points here for submitting bug reports, but please let me know if I'm in the wrong place.

Steps to reproduce:
- create a remote repository at URL with commit(s) in it
  - e.g., a new github repo with README and LICENSE files auto-added
- write some files in a local directory
- git init
- git add .
  - the contents of the directory are now in the index
- git remote add origin URL
- git pull origin master

The local files added to the index are now completely wiped out and replaced with the remote content. I lose all my previous work. :/

This was pretty painful for me to lose a few days of work. I also couldn't stash my changes which I tried first, but git refused without an initial commit.

Would have been nice if git warning me about the destructive operation.

Cheers, Adam

On Sat, Aug 3, 2013 at 9:57 PM, Adam A <hitsthings@gmail.com> wrote:
Show 25 quoted lines
> Hello, the project readme on github points here for submitting bug reports,
> but please let me know if I'm in the wrong place.
>
> Steps to reproduce:
>
> - create a remote repository at URL with commit(s) in it
>   - e.g., a new github repo with README and LICENSE files auto-added
> - write some files in a local directory
> - git init
> - git add .
>   - the contents of the directory are now in the index
> - git remote add origin URL
> - git pull origin master
>
> The local files added to the index are now completely wiped out and replaced
> with the remote content. I lose all my previous work. :/
>
> This was pretty painful for me to lose a few days of work. I also couldn't
> stash my changes which I tried first, but git refused without an initial
> commit.
>
> Would have been nice if git warning me about the destructive operation.
>
> Cheers,
> Adam
Daniel Convissor· Aug 3, 2013, 16:39 UTC · re: Adam A · lore
Hi Adam:
On Sat, Aug 03, 2013 at 10:01:30PM +1000, Adam A wrote:
Show 11 quoted lines
> - create a remote repository at URL with commit(s) in it
>   - e.g., a new github repo with README and LICENSE files auto-added
> - write some files in a local directory
> - git init
> - git add .
>   - the contents of the directory are now in the index
> - git remote add origin URL
> - git pull origin master
> 
> The local files added to the index are now completely wiped out and
> replaced with the remote content. I lose all my previous work. :/

All is not lost. Your local files should be stored in the repository's reflog. Examine the output of "git reflog". You can then reset your working directory to obtain those files by doing something _like_ "git reset --hard HEAD@{1}".

All hail reflog.
Good luck,
--Dan
-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
        4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335
Jonathan Nieder· Aug 3, 2013, 16:57 UTC · re: Daniel Convissor · lore
Daniel Convissor wrote:
> All is not lost.  Your local files should be stored in the repository's
> reflog.  Examine the output of "git reflog".  You can then reset your
> working directory to obtain those files by doing something _like_
> "git reset --hard HEAD@{1}".
Adam hadn't made a commit, so that wouldn't work in this case.

"git fsck --lost-found" should be helpful, but yeah, this is a bug. See for example [1] for the start of a patch to play with (needs tests).

Thanks and hope that helps, Jonathan

[1] http://thread.gmane.org/gmane.comp.version-control.git/196502/focus=196503
Daniel Convissor· Aug 3, 2013, 17:01 UTC · re: Jonathan Nieder · lore
Heya:
On Sat, Aug 03, 2013 at 09:57:28AM -0700, Jonathan Nieder wrote:
> 
> Adam hadn't made a commit, so that wouldn't work in this case.
Oh, good catch.  I saw the add and assumed there was a commit there.
--Dan
-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
        4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335
Adam A· Aug 3, 2013, 21:46 UTC · re: Jonathan Nieder · lore
On Sun, Aug 4, 2013 at 2:57 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 12 quoted lines
> Daniel Convissor wrote:
>
>> All is not lost.  Your local files should be stored in the repository's
>> reflog.  Examine the output of "git reflog".  You can then reset your
>> working directory to obtain those files by doing something _like_
>> "git reset --hard HEAD@{1}".
>
> Adam hadn't made a commit, so that wouldn't work in this case.
>
> "git fsck --lost-found" should be helpful, but yeah, this is a bug.
> See for example [1] for the start of a patch to play with (needs
> tests).

Ah I didn't realize the objects would still be there! `git fsck` + `git show` is a wonderful workaround until the bug is fixed.

Show 5 quoted lines
>
> Thanks and hope that helps,
> Jonathan
>
> [1] http://thread.gmane.org/gmane.comp.version-control.git/196502/focus=196503

Thanks so much guys! Adam

Jeff King· Aug 10, 2013, 07:33 UTC · re: Jonathan Nieder · lore
On Sat, Aug 03, 2013 at 09:57:28AM -0700, Jonathan Nieder wrote:
Show 10 quoted lines
> > All is not lost.  Your local files should be stored in the repository's
> > reflog.  Examine the output of "git reflog".  You can then reset your
> > working directory to obtain those files by doing something _like_
> > "git reset --hard HEAD@{1}".
> 
> Adam hadn't made a commit, so that wouldn't work in this case.
> 
> "git fsck --lost-found" should be helpful, but yeah, this is a bug.
> See for example [1] for the start of a patch to play with (needs
> tests).

If I understand the situation correctly, this is actually already fixed in v1.8.3.3 and higher by b4dc085 (pull: merge into unborn by fast-forwarding from empty tree, 2013-06-20).

-Peff
Daniel Convissor· Aug 3, 2013, 16:59 UTC · re: Daniel Convissor · lore
Hey Again Adam:
On Sat, Aug 03, 2013 at 12:39:15PM -0400, Daniel Convissor wrote:
Show 5 quoted lines
> 
> All is not lost.  Your local files should be stored in the repository's
> reflog.  Examine the output of "git reflog".  You can then reset your
> working directory to obtain those files by doing something _like_
> "git reset --hard HEAD@{1}".

A further thought. The most useful thing to do would probably be along these lines...

git reflog # as mentioned before git checkout -b myinitialstuff HEAD@{<desired number>} git log git checkout master git cherry-pick <hash of your first local commit>

--Dan
-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
        4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335

← back to recent threads