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

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

From
EREric Raible <raible@gmail.com>
Date
Sep 10, 2008, 19:12 UTC
Message-ID
<279b37b20809101212g57e9ad99qbf6fa15888679894@mail.gmail.com>

In http://marc.theaimsgroup.com/?l=git&m=114917892328066 (references by http://git.or.cz/gitwiki/GitFaq), Linus says:

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

Now consider this example:

# 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 git status # -> new file: file42 ls # -> file42, or course git reset --hard ls # -> nothing

I would argue that as a "new file" (as reported by git status) that file42 was never actually tracked by git. Sure, it _would_ have been tracked in the future, but git never actually tracked it (it's not part of any commits).

So in this scenario wouldn't it make more sense for "git reset --hard" to handle file42 as "git reset" does instead of deleting it w/out a trace [1]?

The same question goes for "git checkout -f", too, I suppose.

I actually accidentally deleted hundred of newly added files yesterday doing just this. https://mozy.com/?code=V3D4MM) saved my butt, but it wasn't pleasant.

- Eric

[1] - There's not even a reflog entry. Sure, "git fsck" can be used, but that's hardly a friendly fallback.

Next: Mike Hommey
Message 1 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.