diff mbox series

git-reflog.txt: add an EXAMPLES section

Message ID 20221003084654.183966-1-gitter.spiros@gmail.com (mailing list archive)
State New, archived
Headers show
Series git-reflog.txt: add an EXAMPLES section | expand

Commit Message

Elia Pinto Oct. 3, 2022, 8:46 a.m. UTC
This commit adds an "EXAMPLES" section to the git reflog man page.
This new section currently provides examples of using git reflog
with branches, for which doubts often exist. In this commit we also
add a "SEE ALSO" section which refers to further information
on git commands or documentation referenced in the git reflog man page.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 Documentation/git-reflog.txt | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

Ævar Arnfjörð Bjarmason Oct. 3, 2022, 9:20 a.m. UTC | #1
On Mon, Oct 03 2022, Elia Pinto wrote:

> This commit adds an "EXAMPLES" section to the git reflog man page.
> This new section currently provides examples of using git reflog
> with branches, for which doubts often exist. In this commit we also
> add a "SEE ALSO" section which refers to further information
> on git commands or documentation referenced in the git reflog man page.

I think it can be valuable to have an EXAMPLES section, but:

> +EXAMPLES
> +--------
> +
> +`git reflog`::
> +	Lists entries of reflog of HEAD, starting at `HEAD@{0}`.
> +
> +`git reflog HEAD`::
> +	The same.
> +
> +`git reflog show HEAD`::
> +	The same.
> +
> +`git reflog HEAD@{4}`::
> +	The same, starting at the 4th prior value of HEAD.
> +
> +`git reflog master`::
> +	Lists entries of reflog of `master`.
> +
> +`git reflog master@{0}`::
> +	The same.
> +
> +`git reflog master@{now}`::
> +	The same, show with timestamp.
> +
> +`git reflog master@{4.minutes}`::
> +	The same, starting at master, 4 minutes ago.
> +
> +For the branch that is currently checked out, you can omit the name
> +when you use any of the @{..} notation, so
> +
> +`git reflog @{0}`
> +
> +`git reflog @{now}`
> +
> +are often the easiest ways to view what you did on the current
> +branch

Most of this really just seems to be duplicating "SPECIFYING REVISIONS",
and some of it such as "show with timestamp" is ambiguous/misleading. If
I didn't know how it worked I'd think that it might affect the output
itself (maybe showing times "relative to now"), but it's just
gitrevisions syntax.

> +SEE ALSO
> +--------
> +linkgit:gitrevisions[7],
> +linkgit:git-log[1]

Likewise "SEE ALSO" sections can be really valuable, but they're really
for "now that you've read the above, maybe this is also useful". It's
not a "SEE STUFF YOU SAW BEFORE" :)

In this case we link to these in the first and third paragraphs of the
DESCRIPTION section (respectively), since explaining the revision syntax
etc. is really core to understanding how this command works.

The "SEE ALSO" section is really more for stuff like (in this case)
'git-fsck', 'git-filter-branch', 'git-rev-list' or 'git-stash'. All of
those commansd have some direct interaction with the 'reflog', but are
not mentioned in the main prose.
Bagas Sanjaya Oct. 3, 2022, 1:07 p.m. UTC | #2
On 10/3/22 15:46, Elia Pinto wrote:
> This commit adds an "EXAMPLES" section to the git reflog man page.
> This new section currently provides examples of using git reflog
> with branches, for which doubts often exist. In this commit we also
> add a "SEE ALSO" section which refers to further information
> on git commands or documentation referenced in the git reflog man page.
> 

Better say "Add git-reflog usage examples to the man page."
Also, shouldn't "SEE ALSO" additions be split from this patch?
Elia Pinto Oct. 3, 2022, 1:53 p.m. UTC | #3
Il giorno lun 3 ott 2022 alle ore 11:27 Ævar Arnfjörð Bjarmason
<avarab@gmail.com> ha scritto:
>
>
> On Mon, Oct 03 2022, Elia Pinto wrote:
>
> > This commit adds an "EXAMPLES" section to the git reflog man page.
> > This new section currently provides examples of using git reflog
> > with branches, for which doubts often exist. In this commit we also
> > add a "SEE ALSO" section which refers to further information
> > on git commands or documentation referenced in the git reflog man page.
>
> I think it can be valuable to have an EXAMPLES section, but:
>
> > +EXAMPLES
> > +--------
> > +
> > +`git reflog`::
> > +     Lists entries of reflog of HEAD, starting at `HEAD@{0}`.
> > +
> > +`git reflog HEAD`::
> > +     The same.
> > +
> > +`git reflog show HEAD`::
> > +     The same.
> > +
> > +`git reflog HEAD@{4}`::
> > +     The same, starting at the 4th prior value of HEAD.
> > +
> > +`git reflog master`::
> > +     Lists entries of reflog of `master`.
> > +
> > +`git reflog master@{0}`::
> > +     The same.
> > +
> > +`git reflog master@{now}`::
> > +     The same, show with timestamp.
> > +
> > +`git reflog master@{4.minutes}`::
> > +     The same, starting at master, 4 minutes ago.
> > +
> > +For the branch that is currently checked out, you can omit the name
> > +when you use any of the @{..} notation, so
> > +
> > +`git reflog @{0}`
> > +
> > +`git reflog @{now}`
> > +
> > +are often the easiest ways to view what you did on the current
> > +branch
>
> Most of this really just seems to be duplicating "SPECIFYING REVISIONS",
> and some of it such as "show with timestamp" is ambiguous/misleading. If
> I didn't know how it worked I'd think that it might affect the output
> itself (maybe showing times "relative to now"), but it's just
> gitrevisions syntax.

Thanks a lot, in the meantime.

The examples included are based on an email exchange done here between
a user and a git developer, maybe Junio, I don't remember. The user
found the explanation useful, as he had a hard time understanding how
git-reflog worked with branches. I agree that better could be done,
for example by entering how to recover lost commits, but that was not
the goal at the moment. Later this is something that it is  always
possible to do. It is also true that the examples in practice show
what should already be known with gitrevisions however obviously many
users cannot find the link between the two, I must imagine
>
> > +SEE ALSO
> > +--------
> > +linkgit:gitrevisions[7],
> > +linkgit:git-log[1]
>
> Likewise "SEE ALSO" sections can be really valuable, but they're really
> for "now that you've read the above, maybe this is also useful". It's
> not a "SEE STUFF YOU SAW BEFORE" :)
>
> In this case we link to these in the first and third paragraphs of the
> DESCRIPTION section (respectively), since explaining the revision syntax
> etc. is really core to understanding how this command works.
>
> The "SEE ALSO" section is really more for stuff like (in this case)
> 'git-fsck', 'git-filter-branch', 'git-rev-list' or 'git-stash'. All of
> those commansd have some direct interaction with the 'reflog', but are
> not mentioned in the main prose.
>

Better not to put a "SEE ALSO" then? I personally don't know

>
>
>
>
Junio C Hamano Oct. 3, 2022, 4:31 p.m. UTC | #4
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> On Mon, Oct 03 2022, Elia Pinto wrote:
>
>> This commit adds an "EXAMPLES" section to the git reflog man page.
>> This new section currently provides examples of using git reflog
>> with branches, for which doubts often exist. In this commit we also
>> add a "SEE ALSO" section which refers to further information
>> on git commands or documentation referenced in the git reflog man page.
>
> I think it can be valuable to have an EXAMPLES section, but:
> ...
> Most of this really just seems to be duplicating "SPECIFYING REVISIONS",
> and some of it such as "show with timestamp" is ambiguous/misleading.

It would become immediately clear what these phrases want to say,
when the reader runs "git reflog @{0}" and "git reflog @{now}" while
reading the document.  I am not sure if the description is ambiguous
or misleading to those who haven't seen any reflog output, especially
the timestamped ones.  Perhaps some sample output in the documentation
would help, do you think?

    $ git reflog -2 HEAD@{now}
    ce17cbfa2b HEAD@{Mon Oct 3 09:07:30 2022 -0700}: checkout: moving...
    ce17cbfa2b HEAD@{Mon Oct 3 09:07:14 2022 -0700}: am: ssh signing...
    $ git reflog -2 HEAD@{0}
    ce17cbfa2b HEAD@{0}: checkout: moving...
    ce17cbfa2b HEAD@{1}: am: ssh signing...

I would freely admit that this is one of my least favourite part of
Git UI that allows what comes inside @{} as parameter to "git
reflog" affect both the starting point (e.g. @{2.days} omits the
activities of the past 48 hours) and the format of the output.  The
taste of the design is bad, but it is what we ended up with.

>> +SEE ALSO
>> +--------
>> +linkgit:gitrevisions[7],
>> +linkgit:git-log[1]
>
> Likewise "SEE ALSO" sections can be really valuable, but they're really
> for "now that you've read the above, maybe this is also useful". It's
> not a "SEE STUFF YOU SAW BEFORE" :)
>
> In this case we link to these in the first and third paragraphs of the
> DESCRIPTION section (respectively), since explaining the revision syntax
> etc. is really core to understanding how this command works.

I do not know about that.

Only the part of the revision syntax that refers to the tip of a ref
works as input for "git reflog".  IOW, "git reflog seen^2~4" does
not work.  I do not think the knowledge of revision syntax helps
understanding how to operate the command that much because of the
above.  I agree with you that it is dubious if it is a good idea to
list gitrevisions[7] here, but for an entirely different reason.

On the other hand, git-log[1] might not be a bad thing to refer to,
in order to learn that you can say something like

    git reflog --pretty=short --stat @{now}

Thanks for a review.
Junio C Hamano Oct. 3, 2022, 4:36 p.m. UTC | #5
Bagas Sanjaya <bagasdotme@gmail.com> writes:

> On 10/3/22 15:46, Elia Pinto wrote:
>> This commit adds an "EXAMPLES" section to the git reflog man page.
>> This new section currently provides examples of using git reflog
>> with branches, for which doubts often exist. In this commit we also
>> add a "SEE ALSO" section which refers to further information
>> on git commands or documentation referenced in the git reflog man page.
>> 
>
> Better say "Add git-reflog usage examples to the man page."

Thanks, indeed.

> Also, shouldn't "SEE ALSO" additions be split from this patch?

I think they are better together.  The overall theme is to help
readers of that one documentation page, and 80% of the effort of
this step is spent on adding an EXAMPLES section, while the rest
goes to SEE ALSO.

Thanks.
Junio C Hamano Oct. 3, 2022, 4:40 p.m. UTC | #6
Elia Pinto <gitter.spiros@gmail.com> writes:

> The examples included are based on an email exchange done here between
> a user and a git developer, maybe Junio, I don't remember. The user
> found the explanation useful, as he had a hard time understanding how
> git-reflog worked with branches. I agree that better could be done,
> for example by entering how to recover lost commits, but that was not
> the goal at the moment. Later this is something that it is  always
> possible to do. It is also true that the examples in practice show
> what should already be known with gitrevisions however obviously many
> users cannot find the link between the two, I must imagine

Geez.  I did find the examples, especially the use of "4" as a
random number pulled out of thin air, vaguely familiar.  You seem
to mean https://lore.kernel.org/git/xmqqo7xuif46.fsf@gitster.g/
diff mbox series

Patch

diff --git a/Documentation/git-reflog.txt b/Documentation/git-reflog.txt
index 70791b9fd8..5bbd5958fe 100644
--- a/Documentation/git-reflog.txt
+++ b/Documentation/git-reflog.txt
@@ -96,6 +96,48 @@  them.
 --verbose::
 	Print extra information on screen.
 
+EXAMPLES
+--------
+
+`git reflog`::
+	Lists entries of reflog of HEAD, starting at `HEAD@{0}`.
+
+`git reflog HEAD`::
+	The same.
+
+`git reflog show HEAD`::
+	The same.
+
+`git reflog HEAD@{4}`::
+	The same, starting at the 4th prior value of HEAD.
+
+`git reflog master`::
+	Lists entries of reflog of `master`.
+
+`git reflog master@{0}`::
+	The same.
+
+`git reflog master@{now}`::
+	The same, show with timestamp.
+
+`git reflog master@{4.minutes}`::
+	The same, starting at master, 4 minutes ago.
+
+For the branch that is currently checked out, you can omit the name
+when you use any of the @{..} notation, so
+
+`git reflog @{0}`
+
+`git reflog @{now}`
+
+are often the easiest ways to view what you did on the current
+branch
+
+SEE ALSO
+--------
+linkgit:gitrevisions[7],
+linkgit:git-log[1]
+
 GIT
 ---
 Part of the linkgit:git[1] suite