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

Re: [PATCH] git-checkout.txt: Document

From
EAEd Avis <eda@waniasset.com>
Date
Jun 11, 2015, 10:24 UTC
Message-ID
<loom.20150611T121345-144@post.gmane.org>
In-Reply-To
<xmqq7frbmsce.fsf@gitster.dls.corp.google.com>
>

I agree, the word 'revert' is already taken for the operation of creating a new commit which undoes some earlier commit. So 'revert' cannot be used for the operation of overwriting a working tree file with its contents from the repository.

But just because 'revert' is not a good choice, doesn't mean that 'restore' is either.

>Git is about "contents", not "files".  You modify a file, and
>restore its contents to its pristine state.  It is not "restore the
>file", as Git is not about "files".

'Restore to its pristine state' does convey the flavour of what happens. Plain 'restore' by itself doesn't, really.

>I think "overwrite is better" is primarily coming from not thinking
>in terms of "Git tracks contents, not files".

But 'git checkout .' is primarily an operation on the local filesystem. As far as I know, it does not change the git repository, nor the index, stashes and so on. Its only effect is to create and overwrite local files, much the same as 'tar x'. So the appropriate language to describe it should be based more in common usage rather than git-specific terms - if indeed 'restore' is the git-specific term for replacing a file in the working tree. (In which case why not call the command 'git restore'?)

If indeed it did work by tracking contents, there wouldn't be a problem. The old contents of the file could be saved as a stash and then the file's contents replaced with the version from the current commit.

% git checkout .
The following files have been restored to their pristine state:
   foo
The previous contents have been saved and can be got back with:
   git stash apply checkout_backup_abcde

Then there would be no need for agonizing over the documentation to make it clear that 'git checkout PATH' can be a dangerous operation, because it would no longer be dangerous.

-- 
Ed Avis <eda@waniasset.com>
Previous: Junio C HamanoNext: Torsten Bögershausen
Message 5 of 12 in “git-checkout.txt: Document "git checkout <pathspec>" better”
  1. git-checkout.txt: Document "git checkout <pathspec>" betterTorsten Bögershausen, Jun 8, 2015
  2. Junio C HamanoJun 10, 2015
  3. Ed AvisJun 10, 2015
  4. Junio C HamanoJun 10, 2015
  5. Ed AvisJun 11, 2015
  6. Torsten BögershausenJun 10, 2015
  7. Junio C HamanoJun 11, 2015
  8. Ed AvisJun 11, 2015
  9. Junio C HamanoJun 11, 2015
  10. Scott SchmitJun 12, 2015
  11. Junio C HamanoJun 12, 2015
  12. Torsten BögershausenJun 12, 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.