# git leaves repo in bad state in out-of-space situation

3 messages from 2011-04-17 to 2011-04-17. Participants: Luke Hutchison, Dmitry Potapov.
Thread: https://gitlist.dev/t/27122

## Luke Hutchison, 2011-04-17 06:40

Subject: git leaves repo in bad state in out-of-space situation
Message-ID: <BANLkTi=4EvRZK_bK=JrwiZgfaeHvNgj-dQ@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTi%3D4EvRZK_bK%3DJrwiZgfaeHvNgj-dQ%40mail.gmail.com

```
I just did a git pull and ran out of disk space halfway through, which
left me with a bunch of "Could not create file <filename>" errors.  I
freed up space and tried to repeat the git pull.  Now my repo is
b0rked:

$ git pull
Updating eedace8..a37dbb1
error: Your local changes to the following files would be overwritten by merge:
        <list of some of the pulled files>
Please, commit your changes or stash them before you can merge.
error: The following untracked working tree files would be overwritten by merge:
        <a lot more of the pulled files>

I wasn't sure how to fix this, and this was probably the wrong
response, but I tried "git add . ; git commit -a -m test ; git push"
and got a bunch of merge conflicts due to zero-length binary files
(PNGs etc.).  Repeating this again I get "up to date" but some of my
files have now been replaced in the repo with zero-length versions,
which seems dangerous if I didn't notice it and just assumed that git
had worked its magic and fixed the situation.

I know that gracefully handling out-of-diskspace situations is a pain,
and it's hard to catch each corner case.  But it seems like git could
degrade a little more elegantly in this situation (e.g. files should
not just be created with zero length if there is no disk space left).
Thoughts?

Not sure of the right way to fix my current situation, I'll probably
just overwrite my local copy of the repo with a remote copy using scp
and then try pushing again.

I assume this mailing list is the right place to report bugs, since I
don't see a bug tracker?  I tried looking in the FAQ at
https://git.wiki.kernel.org/index.php/GitFaq , but got:

Database error
A database error has occurred
Query: SELECT lc_value FROM `l10n_cache` WHERE lc_lang = 'en' AND
lc_key = 'deps' LIMIT 1
Function: LCStore_DB::get
Error: 1146 Table 'gitwiki.l10n_cache' doesn't exist (127.0.0.1:4040)

Thanks,
Luke Hutchison

```

## Dmitry Potapov, 2011-04-17 13:38

Subject: Re: git leaves repo in bad state in out-of-space situation
Message-ID: <BANLkTim4=eKQ2wq73Lf5zrjOND-r1n0XCw@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTim4%3DeKQ2wq73Lf5zrjOND-r1n0XCw%40mail.gmail.com
In-Reply-To: <BANLkTi=4EvRZK_bK=JrwiZgfaeHvNgj-dQ@mail.gmail.com>

```
Hi,

On Sun, Apr 17, 2011 at 10:40 AM, Luke Hutchison <luke.hutch@gmail.com> wrote:
> I just did a git pull and ran out of disk space halfway through, which
> left me with a bunch of "Could not create file <filename>" errors.  I
> freed up space and tried to repeat the git pull.  Now my repo is
> b0rked:
>
> $ git pull
> Updating eedace8..a37dbb1
> error: Your local changes to the following files would be overwritten by merge:
>        <list of some of the pulled files>
> Please, commit your changes or stash them before you can merge.
> error: The following untracked working tree files would be overwritten by merge:
>        <a lot more of the pulled files>

The repository is not borked, it's just your working tree is in an
inconsistent state, but it is easy to fix:

git reset --hard HEAD

i.e. to discard all changes in your working tree. BTW, it is not only
useful in the above situation, but when in the process of merging you
discover that you've resolved some conflicts in the wrong way and want
to re-do all merge again.

> I wasn't sure how to fix this, and this was probably the wrong
> response, but I tried "git add . ; git commit -a -m test ; git push"

and that was a silly thing to do... In fact, committing everything
blindly is almost always a bad idea...

BTW, did you mean "git pull" above? Because if you did "git push"
then those bogus changes are at the server now.

> and got a bunch of merge conflicts due to zero-length binary files
> (PNGs etc.).  Repeating this again I get "up to date" but some of my
> files have now been replaced in the repo with zero-length versions,
> which seems dangerous if I didn't notice it and just assumed that git
> had worked its magic and fixed the situation.

git does not do magic, it does exactly what you say. If you said in
the previous commit to change some files to have a zero length then
you should not be surprise that they are empty now.

It always helps to run "gitk --all" to see what you are doing.

> I know that gracefully handling out-of-diskspace situations is a pain,
> and it's hard to catch each corner case.  But it seems like git could
> degrade a little more elegantly in this situation (e.g. files should
> not just be created with zero length if there is no disk space left).
> Thoughts?

Creating or not creating files with zero length would not make any
practical difference here (instead of having zero it would be appeared
removed). There are many situations when checkout (reading files to
the work tree may fail in the middle), for instance, the user could
press CTRL-C, which will leave the working in an inconsistent state.

So, the general solution is only one:

  git reset --hard HEAD


Dmitry

```

## Luke Hutchison, 2011-04-17 19:09

Subject: Re: git leaves repo in bad state in out-of-space situation
Message-ID: <BANLkTimVBVwz7c4=U0-zHhAWztewWYs7Qw@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTimVBVwz7c4%3DU0-zHhAWztewWYs7Qw%40mail.gmail.com
In-Reply-To: <BANLkTim4=eKQ2wq73Lf5zrjOND-r1n0XCw@mail.gmail.com>

```
Hi Dmitry,

On Sun, Apr 17, 2011 at 9:38 AM, Dmitry Potapov <dpotapov@gmail.com> wrote:
> The repository is not borked, it's just your working tree is in an
> inconsistent state, but it is easy to fix:
>
> git reset --hard HEAD

Ah, sounds like my intuition that simply freeing up space and then
re-pulling should have fixed the problem was wrong.  Your explanation
makes sense.

> BTW, did you mean "git pull" above? Because if you did "git push"
> then those bogus changes are at the server now.

No, I work with a centralized repository which requires push
operations.  I know this negates the benefit of distributed SCM.

> It always helps to run "gitk --all" to see what you are doing.
> [...]
> So, the general solution is only one:
>
>  git reset --hard HEAD

Thank you for your patient responses to what turned out to be a very
basic question!  My typical git workflow is very simple and has worked
fine until I ran out of disk space.

Luke

```
