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

7 messages from 2013-08-03 to 2013-08-10. Participants: Adam A, Daniel Convissor, Jonathan Nieder, Jeff King.
Thread: https://gitlist.dev/t/34603

## Adam A, 2013-08-03 12:01

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <CAJOTJ-Cgdg4CQs-3t1CsBkq_feVEpkoASzQSTATiVugjs+LL7w@mail.gmail.com>
URL: https://gitlist.dev/e/CAJOTJ-Cgdg4CQs-3t1CsBkq_feVEpkoASzQSTATiVugjs%2BLL7w%40mail.gmail.com
In-Reply-To: <CAJOTJ-AVamimToPo4oQ=O_Pg+mJHQhardO+NfU8b1dvRxg1KMA@mail.gmail.com>

```
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:
> 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, 2013-08-03 16:39

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <20130803163915.GB945@analysisandsolutions.com>
URL: https://gitlist.dev/e/20130803163915.GB945%40analysisandsolutions.com
In-Reply-To: <CAJOTJ-Cgdg4CQs-3t1CsBkq_feVEpkoASzQSTATiVugjs+LL7w@mail.gmail.com>

```
Hi Adam:

On Sat, Aug 03, 2013 at 10:01:30PM +1000, Adam A wrote:
> - 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, 2013-08-03 16:57

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <20130803165728.GB2893@elie.Belkin>
URL: https://gitlist.dev/e/20130803165728.GB2893%40elie.Belkin
In-Reply-To: <20130803163915.GB945@analysisandsolutions.com>

```
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, 2013-08-03 16:59

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <20130803165923.GD945@analysisandsolutions.com>
URL: https://gitlist.dev/e/20130803165923.GD945%40analysisandsolutions.com
In-Reply-To: <20130803163915.GB945@analysisandsolutions.com>

```
Hey Again Adam:

On Sat, Aug 03, 2013 at 12:39:15PM -0400, 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}".

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

```

## Daniel Convissor, 2013-08-03 17:01

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <20130803170116.GE945@analysisandsolutions.com>
URL: https://gitlist.dev/e/20130803170116.GE945%40analysisandsolutions.com
In-Reply-To: <20130803165728.GB2893@elie.Belkin>

```
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, 2013-08-03 21:46

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <CAJOTJ-D6Aho_NJscXtu74Ok7u5sQmHn_L_Nma_F1kn9O6y95UQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAJOTJ-D6Aho_NJscXtu74Ok7u5sQmHn_L_Nma_F1kn9O6y95UQ%40mail.gmail.com
In-Reply-To: <20130803165728.GB2893@elie.Belkin>

```
On Sun, Aug 4, 2013 at 2:57 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> 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.

>
> 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, 2013-08-10 07:33

Subject: Re: Bug: Pulling remotes into an empty repo deletes the index
Message-ID: <20130810073343.GE30185@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20130810073343.GE30185%40sigill.intra.peff.net
In-Reply-To: <20130803165728.GB2893@elie.Belkin>

```
On Sat, Aug 03, 2013 at 09:57:28AM -0700, Jonathan Nieder 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).

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

```
