git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Init-add-reset bug in a fresh repo
@ 2022-08-07 17:01 Alex A. Davronov
  2022-08-07 17:22 ` Reto
  0 siblings, 1 reply; 2+ messages in thread
From: Alex A. Davronov @ 2022-08-07 17:01 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Init-add-reset bug in a fresh repo
  2022-08-07 17:01 Init-add-reset bug in a fresh repo Alex A. Davronov
@ 2022-08-07 17:22 ` Reto
  0 siblings, 0 replies; 2+ messages in thread
From: Reto @ 2022-08-07 17:22 UTC (permalink / raw)
  To: Alex A. Davronov; +Cc: git

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-07 17:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-07 17:01 Init-add-reset bug in a fresh repo Alex A. Davronov
2022-08-07 17:22 ` Reto

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).