git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RFC: perhaps a "new file" should not be deleted by "git reset --hard"

From
EREric Raible <raible@gmail.com>
Date
Sep 11, 2008, 02:46 UTC
Message-ID
<279b37b20809101946k309ad113neb7d051f1c6c410e@mail.gmail.com>
In-Reply-To
<eafc0afe0809101912v72916d3hce9ae5d6812f0db8@mail.gmail.com>
On Wed, Sep 10, 2008 at 7:12 PM, Changsheng Jiang <jiangzuoyan@gmail.com> wrote:
> I think the current behavior is better than you described. If you want to
> ignore some files, you can added it to the exclude file. All files not
> excluded in the repo directory is maintained by git.

That doesn't really address the problem. This is an updated example that specifically ignores the file:

# Create a single commit in a new repo (so that we have a HEAD) mkdir xx cd xx git init git commit --allow-empty -m"initial" # Add an important file echo "Important stuff" > file42 git add file42 echo file42 > .gitignore git status # -> new file: file42 ls # -> file42, or course git reset --hard ls # -> nothing

So not only was file42 never actually tracked by git (IMHO - I realize that this is debatable) but it was also specifically ignored, and it is _still_ deleted w/out a trace!

I realize that "git reset" will simply unstage the new file in either case (w or w/out .gitignore), but the consequences of an accidental "git reset --hard" are pretty severe in this case. This behavior seems definitely contrary to Linus's explanation:

   And "git reset" won't be deleting files it doesn't track (it had _better_
   not touch them), even more so when it has been told to ignore them, so it
   makes total sense to _not_ delete them when doing that reset.
- Eric
Previous: Eric RaibleNext: Changsheng Jiang
Message 11 of 18 in “RFC: perhaps a "new file" should not be deleted by "git reset --hard"”
  1. Eric RaibleSep 10, 2008
  2. Mike HommeySep 11, 2008
  3. Eric RaibleSep 11, 2008
  4. Changsheng JiangSep 11, 2008
  5. Elijah NewrenSep 11, 2008
  6. Eric RaibleSep 11, 2008
  7. Junio C HamanoSep 11, 2008
  8. Eric RaibleSep 11, 2008
  9. Jeff WhitesideSep 11, 2008
  10. Eric RaibleSep 11, 2008
  11. Eric RaibleSep 11, 2008
  12. Changsheng JiangSep 11, 2008
  13. Eric RaibleSep 11, 2008
  14. Elijah NewrenSep 11, 2008
  15. Eric RaibleSep 11, 2008
  16. Miklos VajnaSep 11, 2008
  17. Eric RaibleSep 11, 2008
  18. Miklos VajnaSep 12, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.