# Init-add-reset bug in a fresh repo

2 messages from 2022-08-07 to 2022-08-07. Participants: Alex A. Davronov, Reto.
Thread: https://gitlist.dev/t/58276

## Alex A. Davronov, 2022-08-07 17:01

Subject: Init-add-reset bug in a fresh repo
Message-ID: <CAKBAyV4XaXC=Gw5SN9So9UAMJ9ZQE=8dA7B5D8+Wn4JKuFRDeA@mail.gmail.com>
URL: https://gitlist.dev/e/CAKBAyV4XaXC%3DGw5SN9So9UAMJ9ZQE%3D8dA7B5D8%2BWn4JKuFRDeA%40mail.gmail.com

```
Steps to reproduce your issue

If you have files in a folder and then initiate-add-reset git
then you lose everything:

Run the following in your bash shell to see:
    clear; \
    [[ -d /tmp/evilgit ]] && rm -rdI /tmp/evilgit; \
    mkdir /tmp/evilgit/; \
    cd /tmp/evilgit/; \
    echo "----------------- Create some files:"; \
    pwd; \
    echo -n "ls -l: "; \
    touch a.txt b.txt c.txt; \
    ls; \
    echo "----------------- Now, init the repo:"; \
    echo -n "git init: "; \
    git init 2> /dev/null; \
    echo "git add: a.txt b.txt c.txt"; \
    git add ./*; \
    echo -n "git reset --hard: "; \
    git reset --hard; \
    echo "\n----------------- Check files again:"; \
    echo "ls -l: "; \
    ls; \
    echo "No files! " ; \
    echo "\n----------------- Now, all the files we have created are gone!"; \
    cd .. ; \
    rm -rdI /tmp/evilgit


What did you expect to happen? (Expected behavior)
- Files created prior to repo aren't getting removed
- OR
- git user is warned that the files are going to get deleted if
resetting hard indexed ones

What happened instead? (Actual behavior)
- Files are gone.

What's different between what you expected and what actually happened?
- Pre-existing files should be kept

Anything else you want to add:

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.37.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 5.15.0-43-generic #46-Ubuntu SMP Tue Jul 12 10:30:17 UTC
2022 x86_64
compiler info: gnuc: 11.2
libc info: glibc: 2.35
$SHELL (typically, interactive shell): /usr/bin/zsh


[Enabled Hooks]

[Additional info]
See for reference:
- https://gist.github.com/hinell/e023bad4652364b477decb036fc6a60a

```

## Reto, 2022-08-07 17:22

Subject: Re: Init-add-reset bug in a fresh repo
Message-ID: <20220807172220.z35ilb4z3xyywkor@feather>
URL: https://gitlist.dev/e/20220807172220.z35ilb4z3xyywkor%40feather
In-Reply-To: <CAKBAyV4XaXC=Gw5SN9So9UAMJ9ZQE=8dA7B5D8+Wn4JKuFRDeA@mail.gmail.com>

```
> What did you expect to happen? (Expected behavior)
> - Files created prior to repo aren't getting removed

> What happened instead? (Actual behavior)
> - Files are gone.

That's literally what you instructed git to do...

--hard really means that, reset I don't care YOLO, --force, just do it
mate.

>--hard
>   Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
>   Any untracked files or directories in the way of writing any tracked files are simply deleted.

In other words, the flag does exactly what it's meant to do.

Kind regards,
Reto

```
