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

Re: Suggestion: make git checkout safer

From
EAEd Avis <eda@waniasset.com>
Date
Jun 4, 2015, 10:47 UTC
Message-ID
<loom.20150604T123949-199@post.gmane.org>
In-Reply-To
<CAGZ79kYv5Xgfv=3KD0oPrUsJD2Yw-EHu7U=_35FZTm4Rp5hbBA@mail.gmail.com>
Stefan Beller <sbeller <at> google.com> writes:
>So in one mode, we do actually warn about contents going missing, and the
>other mode is designed to actually make things go missing without any
>warning.

I think this is a big part of the issue. Two rather different operations are given the name 'checkout', and the safety standards applied to them also differ greatly. The manual page doesn't make it clear that it can be quite a dangerous command to run, even without --force.

>If I were to come up with a name for such an action it's
>maybe "reset" or "reset-file(s)".

Agreed. Or 'git clean' could become more powerful and able to reset file contents as well as deleting untracked files. The name and documentation of 'git clean' already make it clear that it's not something safe to run without thinking first.

Julio H. asked how I had learned to run 'git checkout .'. I think it was just word of mouth. I had deleted some files from the working tree and asked a colleague how to restore them from the repository - which is, after all, a bread-and-butter operation for any version control system. What is the correct command to run, then, to safely restore missing files?

And yes, it probably would be better to use git's native mechanisms to throw away local changes to a file, rather than the sledgehammer approach of just deleting it and checking it out again. Most of the time I do so. Sometimes when everything is a real mess it is more straighforward to reach for 'rm' - or indeed for the delete option in your IDE or file browser.

-- 
Ed Avis <eda@waniasset.com>
Previous: Stefan BellerNext: Ed Avis
Message 11 of 28 in “Suggestion: make git checkout safer”
  1. Ed AvisJun 3, 2015
  2. Jeff KingJun 3, 2015
  3. Ed AvisJun 3, 2015
  4. Jeff KingJun 3, 2015
  5. Ed AvisJun 3, 2015
  6. Junio C HamanoJun 3, 2015
  7. Randall S. BeckerJun 3, 2015
  8. Junio C HamanoJun 3, 2015
  9. Randall S. BeckerJun 3, 2015
  10. Stefan BellerJun 3, 2015
  11. Ed AvisJun 4, 2015
  12. Ed AvisJun 4, 2015
  13. Torsten BögershausenJun 3, 2015
  14. Kevin DaudtJun 3, 2015
  15. Ed AvisJun 4, 2015
  16. Torsten BögershausenJun 4, 2015
  17. Ed AvisJun 5, 2015
  18. Duy NguyenJun 5, 2015
  19. Eric SunshineJun 5, 2015
  20. Junio C HamanoJun 5, 2015
  21. Ed AvisJun 5, 2015
  22. Eric SunshineJun 5, 2015
  23. Philip OakleyJun 3, 2015
  24. Junio C HamanoJun 3, 2015
  25. Jeff KingJun 3, 2015
  26. Randall S. BeckerJun 3, 2015
  27. Junio C HamanoJun 3, 2015
  28. John SzakmeisterJun 4, 2015

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.