{"thread":{"id":"48337","subject":"[USABILITY] git-reset removes directories","startedAt":"2018-04-21T02:58:48Z","lastAt":"2018-04-21T02:58:48Z","messageCount":1,"participants":["Yutian Li"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"345294","messageId":"CABvSBngwh_C5dna=U9dLpg3r=BWQH8imsa-3q=yiLFeYdbT17Q@mail.gmail.com","threadId":"48337","inReplyTo":null,"subject":"[USABILITY] git-reset removes directories","fromName":"Yutian Li","fromEmail":"hotpxless@gmail.com","sentAt":"2018-04-21T02:58:43Z","receivedAt":"2018-04-21T02:58:48Z","isPatch":false,"sender":{"key":"hotpxless@gmail.com","avatar":null},"body":"Ok I have been bitten by this issue twice. :(\n\n`git reset --hard` will reset modifications in the working directory\n(of course). But if I remove a file, add a directory with the same\nname, `git reset --hard` will erase that whole directory.\nSpecifically the following steps:\n```\ntouch file\ngit add file\ngit commit -m \"add file\"\n# now the HEAD is constructed\nrm file\nmkdir file\ntouch file/a\n# now here is the issue\ngit reset --hard # this will remove the directory and all its files\n```\n\nI guess this has to do with Git not tracking \"changing a file to a\ndirectory\", especially because one is a blob and another is a tree.\n\nIn case of `git reset --hard`, people would expect reverting\nmodifications, bringing up removed files, but not removing a whole\ndirectory with the same name. Especially if the directory is already\npopulated. Then the whole thing is gone.\nI think it would better if Git could output a warning and abort, like\nin case of checkout (\"Updating the following ... would lose ...\").\n\nBut honestly I usually take `git reset --hard` seriously and will\ndouble check before invocation. What actually bit me was `git stash`.\nIt will call `git reset --hard -q` after saving the working directory.\nBut in the case I just described, since the new directory is not\ntracked, it will not be saved and will be erased. `git stash` usually\ngives me the mental model of \"saving stuff in working directory\", but\nnot like in this case where it also deletes stuff in working\ndirectory.\n"}]}