git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Alex A. Davronov" <al.neodim@gmail.com>
To: git@vger.kernel.org
Subject: Init-add-reset bug in a fresh repo
Date: Sun, 7 Aug 2022 20:01:21 +0300	[thread overview]
Message-ID: <CAKBAyV4XaXC=Gw5SN9So9UAMJ9ZQE=8dA7B5D8+Wn4JKuFRDeA@mail.gmail.com> (raw)

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

             reply	other threads:[~2022-08-07 17:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-07 17:01 Alex A. Davronov [this message]
2022-08-07 17:22 ` Init-add-reset bug in a fresh repo Reto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKBAyV4XaXC=Gw5SN9So9UAMJ9ZQE=8dA7B5D8+Wn4JKuFRDeA@mail.gmail.com' \
    --to=al.neodim@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).