git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [USABILITY] git-reset removes directories
@ 2018-04-21  2:58 Yutian Li
  0 siblings, 0 replies; only message in thread
From: Yutian Li @ 2018-04-21  2:58 UTC (permalink / raw)
  To: git

Ok I have been bitten by this issue twice. :(

`git reset --hard` will reset modifications in the working directory
(of course). But if I remove a file, add a directory with the same
name, `git reset --hard` will erase that whole directory.
Specifically the following steps:
```
touch file
git add file
git commit -m "add file"
# now the HEAD is constructed
rm file
mkdir file
touch file/a
# now here is the issue
git reset --hard # this will remove the directory and all its files
```

I guess this has to do with Git not tracking "changing a file to a
directory", especially because one is a blob and another is a tree.

In case of `git reset --hard`, people would expect reverting
modifications, bringing up removed files, but not removing a whole
directory with the same name. Especially if the directory is already
populated. Then the whole thing is gone.
I think it would better if Git could output a warning and abort, like
in case of checkout ("Updating the following ... would lose ...").

But honestly I usually take `git reset --hard` seriously and will
double check before invocation. What actually bit me was `git stash`.
It will call `git reset --hard -q` after saving the working directory.
But in the case I just described, since the new directory is not
tracked, it will not be saved and will be erased. `git stash` usually
gives me the mental model of "saving stuff in working directory", but
not like in this case where it also deletes stuff in working
directory.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-04-21  2:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-21  2:58 [USABILITY] git-reset removes directories Yutian Li

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).