threads / patch / 39565

patchgit-checkout.txt: Document "git checkout <pathspec>" better

Subject: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

## tl;dr

12 messages between Jun 8, 2015 and Jun 12, 2015. Diffs are folded; open one to read it.

replies: 11people: 4as markdown or json

Torsten Bögershausen· Jun 8, 2015, 20:21 UTC · lore
git checkout <pathspec> can be used to revert changes in the working tree.
Signed-off-by: Torsten Bögershausen <tboegi@web.de>
---
My first attempt to improve the documentation
 Documentation/git-checkout.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Show changes to Documentation/git-checkout.txt +3 −2
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index d263a56..8cd018a 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -3,7 +3,7 @@ git-checkout(1)
 
 NAME
 ----
-git-checkout - Checkout a branch or paths to the working tree
+git-checkout - Switch branches or reverts changes in the working tree
 
 SYNOPSIS
 --------
@@ -83,7 +83,8 @@ Omitting <branch> detaches HEAD at the tip of the current branch.
 	When <paths> or `--patch` are given, 'git checkout' does *not*
 	switch branches.  It updates the named paths in the working tree
 	from the index file or from a named <tree-ish> (most often a
-	commit).  In this case, the `-b` and `--track` options are
+	commit).  Changes in files are discarded and deleted files are
+	restored. In this case, the `-b` and `--track` options are
 	meaningless and giving either of them results in an error.  The
 	<tree-ish> argument can be used to specify a specific tree-ish
 	(i.e.  commit, tag or tree) to update the index for the given
-- 
2.2.0.rc1.790.ge19fcd2
Junio C Hamano· Jun 10, 2015, 15:05 UTC · re: Torsten Bögershausen · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

Torsten Bögershausen <tboegi@web.de> writes:
> git checkout <pathspec> can be used to revert changes in the working tree.

I somehow thought that concensus in the recent thread was that "restore", not "revert", is the more appropriate wording?

And I think that is indeed sensible because "revert" (or "reset") already means something else in Git (and in other systems), while "restore" does not have a confusing connotation. It can only mean "overwrite with a pristine copy", which is what the command is about.

> -git-checkout - Checkout a branch or paths to the working tree
> +git-checkout - Switch branches or reverts changes in the working tree

Two verbs in different moods; either "switch branches or restore changes" or "switches branches or restores changes" would fix that, and judging from "git help" output, I think we want to go with the former, i.e. "switch branches or restore changes".

Show 10 quoted lines
>  
>  SYNOPSIS
>  --------
> @@ -83,7 +83,8 @@ Omitting <branch> detaches HEAD at the tip of the current branch.
>  	When <paths> or `--patch` are given, 'git checkout' does *not*
>  	switch branches.  It updates the named paths in the working tree
>  	from the index file or from a named <tree-ish> (most often a
> -	commit).  In this case, the `-b` and `--track` options are
> +	commit).  Changes in files are discarded and deleted files are
> +	restored.

I see we are suffering from the common disease of giving one explanation and then realizing that first explanation can be misread, clarifying it by more explanation, after reading the updated text three times. Let's instead try to clarify the first explanation to make it harder to misread.

In this case, "updates X from Y" is what causes misunderstanding, as "updates" does not necessarily mean "restores with the original".

How about this?
  	'git checkout' with <paths> or `--patch` is used to restore
        modified or deleted paths to their original contents from
        the index file or from a named <tree-ish> (most often a
        commit) without switching branches.
Ed Avis· Jun 10, 2015, 15:11 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

'restore' may be more consistent with git's internal terminology. But from an outsider's perspective, 'revert' rather than 'restore' is in my view much clearer and more consistent with other version control systems: for example 'svn revert' is what you use to revert files in the working copy.

The original issue was that I naively expected that 'git checkout PATH' would indeed just 'restore' some files, that is, create them when they are missing. Its action is rather more drastic than that.

If 'revert' is not a suitable verb because of the existing git-revert, then I suggest that 'overwrite' or 'replace' might better convey the idea of what the command does.

-- 
Ed Avis <eda@waniasset.com>
Junio C Hamano· Jun 10, 2015, 16:38 UTC · re: Ed Avis · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

Ed Avis <eda@waniasset.com> writes:
> 'restore' may be more consistent with git's internal terminology.
> But from an outsider's perspective, 'revert' rather than 'restore' is in my
> view much clearer and more consistent with other version control systems:
> for example 'svn revert' is what you use to revert files in the working copy.

The reason why I said "restore" is because it does *not* have any "internal terminology" connotation.

On the other hand, "revert" that means "create a counter-effect commit" is not "internal". "git revert" is a part of end-user facing command.

The only people that will be helped by using "revert" there will be the ones who haven't learned "git revert". And it will make it harder for them to learn "git revert". It is unfortunate that other systems use the word "revert" in a different way, and that is why we should avoid using that word when describing "checkout".

Show 6 quoted lines
> The original issue was that I naively expected that 'git checkout PATH' would
> indeed just 'restore' some files, that is, create them when they are missing.
> ...
> If 'revert' is not a suitable verb because of the existing git-revert, then
> I suggest that 'overwrite' or 'replace' might better convey the idea of what
> the command does.

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

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

Ed Avis· Jun 11, 2015, 10:24 UTC · re: Junio C Hamano · lore

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

>

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>
Torsten Bögershausen· Jun 10, 2015, 18:27 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

On 2015-06-10 17.05, Junio C Hamano wrote:
> Torsten Bögershausen <tboegi@web.de> writes:
> 
(Need to drop Eric from CC-list( 
Show 18 quoted lines
>> git checkout <pathspec> can be used to revert changes in the working tree.
> 
> I somehow thought that concensus in the recent thread was that
> "restore", not "revert", is the more appropriate wording?
> 
> And I think that is indeed sensible because "revert" (or "reset")
> already means something else in Git (and in other systems), while
> "restore" does not have a confusing connotation.  It can only mean
> "overwrite with a pristine copy", which is what the command is
> about.
> 
>> -git-checkout - Checkout a branch or paths to the working tree
>> +git-checkout - Switch branches or reverts changes in the working tree
> 
> Two verbs in different moods; either "switch branches or restore
> changes" or "switches branches or restores changes" would fix that,
> and judging from "git help" output, I think we want to go with the
> former, i.e. "switch branches or restore changes".
OK for me
Show 12 quoted lines
> 
>>  
>>  SYNOPSIS
>>  --------
>> @@ -83,7 +83,8 @@ Omitting <branch> detaches HEAD at the tip of the current branch.
>>  	When <paths> or `--patch` are given, 'git checkout' does *not*
>>  	switch branches.  It updates the named paths in the working tree
>>  	from the index file or from a named <tree-ish> (most often a
>> -	commit).  In this case, the `-b` and `--track` options are
>> +	commit).  Changes in files are discarded and deleted files are
>> +	restored.
> 
[]
Show 6 quoted lines
> How about this?
> 
>   	'git checkout' with <paths> or `--patch` is used to restore
>         modified or deleted paths to their original contents from
>         the index file or from a named <tree-ish> (most often a
>         commit) without switching branches.
OK for me.
Junio C Hamano· Jun 11, 2015, 14:47 UTC · re: Torsten Bögershausen · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

Torsten Bögershausen <tboegi@web.de> writes:
Show 9 quoted lines
> On 2015-06-10 17.05, Junio C Hamano wrote:
>
>>> -git-checkout - Checkout a branch or paths to the working tree
>>> +git-checkout - Switch branches or reverts changes in the working tree
>> 
>> Two verbs in different moods; either "switch branches or restore
>> changes" or "switches branches or restores changes" would fix that,
>> and judging from "git help" output, I think we want to go with the
>> former, i.e. "switch branches or restore changes".

Gaah, no we do not "restore" changes. We "restore" working tree files to their pristine state.

And "... or restore working tree files to their pristine state" is way too long.

Unfortunately "overwrite changes in the working tree" is even worse. As it does not say overwrite _with what_, we invite the original confusion that triggered this whole thread if the reader thought an equally useful but different "overwrites with result of merging your local changes to the pristine" (similar to what "checkout -m" does) would happen.

At least, "restore working tree files" without saying "restoring them to what state?" is much less likely to cause such a confusion.

So...
    git-checkout - Switch branches or restore working tree files
perhaps?
Junio C Hamano· Jun 11, 2015, 18:23 UTC · re: Ed Avis · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

Ed Avis <eda@waniasset.com> writes:
> I guess 'replace' would be a better word than 'restore' for the current
> behaviour.

Hmm, but wouldn't replace have the same issue as overwrite, namely, 'replace with what?'.

Scott Schmit· Jun 12, 2015, 04:49 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

On Wed, Jun 10, 2015 at 08:05:32AM -0700, Junio C Hamano wrote:
Show 47 quoted lines
> Torsten Bögershausen <tboegi@web.de> writes:
> 
> > git checkout <pathspec> can be used to revert changes in the working tree.
> 
> I somehow thought that concensus in the recent thread was that
> "restore", not "revert", is the more appropriate wording?
> 
> And I think that is indeed sensible because "revert" (or "reset")
> already means something else in Git (and in other systems), while
> "restore" does not have a confusing connotation.  It can only mean
> "overwrite with a pristine copy", which is what the command is
> about.
> 
> > -git-checkout - Checkout a branch or paths to the working tree
> > +git-checkout - Switch branches or reverts changes in the working tree
> 
> Two verbs in different moods; either "switch branches or restore
> changes" or "switches branches or restores changes" would fix that,
> and judging from "git help" output, I think we want to go with the
> former, i.e. "switch branches or restore changes".
> 
> >  
> >  SYNOPSIS
> >  --------
> > @@ -83,7 +83,8 @@ Omitting <branch> detaches HEAD at the tip of the current branch.
> >  	When <paths> or `--patch` are given, 'git checkout' does *not*
> >  	switch branches.  It updates the named paths in the working tree
> >  	from the index file or from a named <tree-ish> (most often a
> > -	commit).  In this case, the `-b` and `--track` options are
> > +	commit).  Changes in files are discarded and deleted files are
> > +	restored.
> 
> I see we are suffering from the common disease of giving one
> explanation and then realizing that first explanation can be
> misread, clarifying it by more explanation, after reading the
> updated text three times.  Let's instead try to clarify the first
> explanation to make it harder to misread.
> 
> In this case, "updates X from Y" is what causes misunderstanding, as
> "updates" does not necessarily mean "restores with the original".
> 
> How about this?
> 
>   	'git checkout' with <paths> or `--patch` is used to restore
>         modified or deleted paths to their original contents from
>         the index file or from a named <tree-ish> (most often a
>         commit) without switching branches.
I think these changes would improve the above:
s/index file/index/
- index file is implementation; the glossary only defines "index"
s/or from/or replace paths with the contents from/
- the latter case isn't always restoration, if <tree-ish> doesn't come
  from an ancestor of HEAD (so I don't like "restore" in the summary
  either)
s/without switching/instead of switching/
- 'without' implies it makes sense to restore/replace with switching
  branches, but we've chosen not to.  (I then waste time trying to
  understand that)
s/commit/commit-ish/
- tags are also tree-ishes, though you could argue this case is less
  "often"
leaving:

'git checkout' with <paths> or `--patch` is used to restore modified or deleted paths to their original contents from the index or replace paths with the contents from a named <tree-ish> (most often a commit-ish) instead of switching branches.

does a sha1 count as "named"? Maybe s/named //.
-- 
Scott Schmit
Junio C Hamano· Jun 12, 2015, 16:24 UTC · re: Scott Schmit · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

Scott Schmit <i.grok@comcast.net> writes:
Show 13 quoted lines
> On Wed, Jun 10, 2015 at 08:05:32AM -0700, Junio C Hamano wrote:
>
>> How about this?
>> 
>>         'git checkout' with <paths> or `--patch` is used to restore
>>         modified or deleted paths to their original contents from
>>         the index file or from a named <tree-ish> (most often a
>>         commit) without switching branches.
>
> I think these changes would improve the above:
>
> s/index file/index/
> - index file is implementation; the glossary only defines "index"
Yup, that was sloppy of me.  Thanks.
> s/or from/or replace paths with the contents from/
> - the latter case isn't always restoration, if <tree-ish> doesn't come
>   from an ancestor of HEAD (so I don't like "restore" in the summary
>   either)
Yes, that is why the original said 'checkout' in the first place.
> s/without switching/instead of switching/
> - 'without' implies it makes sense to restore/replace with switching
>   branches, but we've chosen not to.  (I then waste time trying to
>   understand that)
OK.
> s/commit/commit-ish/
> - tags are also tree-ishes, though you could argue this case is less
>   "often"
Correct.
Show 6 quoted lines
> leaving:
>
> 'git checkout' with <paths> or `--patch` is used to restore modified or
> deleted paths to their original contents from the index or replace paths
> with the contents from a named <tree-ish> (most often a commit-ish)
> instead of switching branches.

Yeah, I like that. I'd appreciate if somebody can submit the final version as a patch form after waiting for a few days to hear other's opinions.

> does a sha1 count as "named"? Maybe s/named //.

The "named" in the original "named tree-ish" does not mean "the tree-ish has a human readable name (e.g. a tag)"; it merely means "the user tells Git to use one tree-ish to use for this operation; and the tree-ish was specified (by some means) by the user", i.e. the same thing as "specified". If you specify the tree-ish with its object name, yes, you are naming that (after all, that is what everything in sha1-name.c does).

s/a named <tree-ish>/the <tree-ish>/ in the improved text you proposed above would be sufficient, I would think, as it is clear which <tree-ish> we are talking about in the context.

Thanks.
Torsten Bögershausen· Jun 12, 2015, 20:41 UTC · re: Scott Schmit · lore

Re: [PATCH] git-checkout.txt: Document "git checkout <pathspec>" better

On 2015-06-12 06.49, Scott Schmit wrote:
> 'git checkout' with <paths> or `--patch` is used to restore modified or
> deleted paths to their original contents from the index or replace paths
> with the contents from a named <tree-ish> (most often a commit-ish)
> instead of switching branches.

------------------- I will probably send a patch, the next days or so. It feels as if we can split the long sentence, and differntiate between the "restore" and "copy content from other tree-sh". How about this:

'git checkout' [--] <pathspec>...::
	'git checkout' with <paths> is used to restore modified or
	deleted paths to their original contents from the index.
'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
	'git checkout' with [<tree-ish>] and <paths> or `--patch` is used
	to replace <paths> with the contents from a named <tree-ish>
	(most often a commit-ish) instead of switching branches.
	In this case, the `-b` and `--track` options are
	meaningless and giving either of them results in an error.  The
	<tree-ish> argument can be used to specify a specific tree-ish
	(i.e.  commit, tag or tree) to update the index for the given
	paths before updating the working tree.
+

← back to recent threads