builtin/reflog: improve grouping of subcommands

The way subcommands of git-reflog(1) are laid out does not make any immediate sense. Reorder them such that read-only subcommands precede writing commands for a bit more structure. Furthermore, move the "expire" subcommand last. This prepares for a subsequent change where we are about to introduce a new "write" command to append reflog entries. Like this, the writing subcommands are ordered such that those affecting a single reflog come before those spanning across all reflogs. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 6, 2025 at 07:54 UTC 649c7bb77a173c6ef2c27fc64b8689aee9b0b8a8
2 files changed +50 -49
Documentation/git-reflog.adoc
+31 -30
@@ -11,13 +11,13 @@ SYNOPSIS
11 [synopsis]
12 git reflog [show] [<log-options>] [<ref>]
13 git reflog list
14 -git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
15 - [--rewrite] [--updateref] [--stale-fix]
16 - [--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>...]
14 +git reflog exists <ref>
15 git reflog delete [--rewrite] [--updateref]
16 [--dry-run | -n] [--verbose] <ref>@{<specifier>}...
17 git reflog drop [--all [--single-worktree] | <refs>...]
20 -git reflog exists <ref>
18 +git reflog expire [--expire=<time>] [--expire-unreachable=<time>]
19 + [--rewrite] [--updateref] [--stale-fix]
20 + [--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>...]
21
22 DESCRIPTION
23 -----------
@@ -43,11 +43,9 @@ actions, and in addition the `HEAD` reflog records branch switching.
43
44 The "list" subcommand lists all refs which have a corresponding reflog.
45
46 -The "expire" subcommand prunes older reflog entries. Entries older
47 -than `expire` time, or entries older than `expire-unreachable` time
48 -and not reachable from the current tip, are removed from the reflog.
49 -This is typically not used directly by end users -- instead, see
50 -linkgit:git-gc[1].
46 +The "exists" subcommand checks whether a ref has a reflog. It exits
47 +with zero status if the reflog exists, and non-zero status if it does
48 +not.
49
50 The "delete" subcommand deletes single entries from the reflog, but
51 not the reflog itself. Its argument must be an _exact_ entry (e.g. "`git
@@ -58,9 +56,11 @@ The "drop" subcommand completely removes the reflog for the specified
56 references. This is in contrast to "expire" and "delete", both of which
57 can be used to delete reflog entries, but not the reflog itself.
58
61 -The "exists" subcommand checks whether a ref has a reflog. It exits
62 -with zero status if the reflog exists, and non-zero status if it does
63 -not.
59 +The "expire" subcommand prunes older reflog entries. Entries older
60 +than `expire` time, or entries older than `expire-unreachable` time
61 +and not reachable from the current tip, are removed from the reflog.
62 +This is typically not used directly by end users -- instead, see
63 +linkgit:git-gc[1].
64
65 OPTIONS
66 -------
@@ -71,6 +71,25 @@ Options for `show`
71 `git reflog show` accepts any of the options accepted by `git log`.
72
73
74 +Options for `delete`
75 +~~~~~~~~~~~~~~~~~~~~
76 +
77 +`git reflog delete` accepts options `--updateref`, `--rewrite`, `-n`,
78 +`--dry-run`, and `--verbose`, with the same meanings as when they are
79 +used with `expire`.
80 +
81 +Options for `drop`
82 +~~~~~~~~~~~~~~~~~~
83 +
84 +`--all`::
85 + Drop the reflogs of all references from all worktrees.
86 +
87 +`--single-worktree`::
88 + By default when `--all` is specified, reflogs from all working
89 + trees are dropped. This option limits the processing to reflogs
90 + from the current working tree only.
91 +
92 +
93 Options for `expire`
94 ~~~~~~~~~~~~~~~~~~~~
95
@@ -130,24 +149,6 @@ which didn't protect objects referred to by reflogs.
149 Print extra information on screen.
150
151
133 -Options for `delete`
134 -~~~~~~~~~~~~~~~~~~~~
135 -
136 -`git reflog delete` accepts options `--updateref`, `--rewrite`, `-n`,
137 -`--dry-run`, and `--verbose`, with the same meanings as when they are
138 -used with `expire`.
139 -
140 -Options for `drop`
141 -~~~~~~~~~~~~~~~~~~
142 -
143 -`--all`::
144 - Drop the reflogs of all references from all worktrees.
145 -
146 -`--single-worktree`::
147 - By default when `--all` is specified, reflogs from all working
148 - trees are dropped. This option limits the processing to reflogs
149 - from the current working tree only.
150 -
152 GIT
153 ---
154 Part of the linkgit:git[1] suite
builtin/reflog.c
+19 -19
@@ -17,21 +17,21 @@
17 #define BUILTIN_REFLOG_LIST_USAGE \
18 N_("git reflog list")
19
20 -#define BUILTIN_REFLOG_EXPIRE_USAGE \
21 - N_("git reflog expire [--expire=<time>] [--expire-unreachable=<time>]\n" \
22 - " [--rewrite] [--updateref] [--stale-fix]\n" \
23 - " [--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>...]")
20 +#define BUILTIN_REFLOG_EXISTS_USAGE \
21 + N_("git reflog exists <ref>")
22
23 #define BUILTIN_REFLOG_DELETE_USAGE \
24 N_("git reflog delete [--rewrite] [--updateref]\n" \
25 " [--dry-run | -n] [--verbose] <ref>@{<specifier>}...")
26
29 -#define BUILTIN_REFLOG_EXISTS_USAGE \
30 - N_("git reflog exists <ref>")
31 -
27 #define BUILTIN_REFLOG_DROP_USAGE \
28 N_("git reflog drop [--all [--single-worktree] | <refs>...]")
29
30 +#define BUILTIN_REFLOG_EXPIRE_USAGE \
31 + N_("git reflog expire [--expire=<time>] [--expire-unreachable=<time>]\n" \
32 + " [--rewrite] [--updateref] [--stale-fix]\n" \
33 + " [--dry-run | -n] [--verbose] [--all [--single-worktree] | <refs>...]")
34 +
35 static const char *const reflog_show_usage[] = {
36 BUILTIN_REFLOG_SHOW_USAGE,
37 NULL,
@@ -42,9 +42,9 @@ static const char *const reflog_list_usage[] = {
42 NULL,
43 };
44
45 -static const char *const reflog_expire_usage[] = {
46 - BUILTIN_REFLOG_EXPIRE_USAGE,
47 - NULL
45 +static const char *const reflog_exists_usage[] = {
46 + BUILTIN_REFLOG_EXISTS_USAGE,
47 + NULL,
48 };
49
50 static const char *const reflog_delete_usage[] = {
@@ -52,23 +52,23 @@ static const char *const reflog_delete_usage[] = {
52 NULL
53 };
54
55 -static const char *const reflog_exists_usage[] = {
56 - BUILTIN_REFLOG_EXISTS_USAGE,
57 - NULL,
58 -};
59 -
55 static const char *const reflog_drop_usage[] = {
56 BUILTIN_REFLOG_DROP_USAGE,
57 NULL,
58 };
59
60 +static const char *const reflog_expire_usage[] = {
61 + BUILTIN_REFLOG_EXPIRE_USAGE,
62 + NULL
63 +};
64 +
65 static const char *const reflog_usage[] = {
66 BUILTIN_REFLOG_SHOW_USAGE,
67 BUILTIN_REFLOG_LIST_USAGE,
68 - BUILTIN_REFLOG_EXPIRE_USAGE,
68 + BUILTIN_REFLOG_EXISTS_USAGE,
69 BUILTIN_REFLOG_DELETE_USAGE,
70 BUILTIN_REFLOG_DROP_USAGE,
71 - BUILTIN_REFLOG_EXISTS_USAGE,
71 + BUILTIN_REFLOG_EXPIRE_USAGE,
72 NULL
73 };
74
@@ -404,10 +404,10 @@ int cmd_reflog(int argc,
404 struct option options[] = {
405 OPT_SUBCOMMAND("show", &fn, cmd_reflog_show),
406 OPT_SUBCOMMAND("list", &fn, cmd_reflog_list),
407 - OPT_SUBCOMMAND("expire", &fn, cmd_reflog_expire),
408 - OPT_SUBCOMMAND("delete", &fn, cmd_reflog_delete),
407 OPT_SUBCOMMAND("exists", &fn, cmd_reflog_exists),
408 + OPT_SUBCOMMAND("delete", &fn, cmd_reflog_delete),
409 OPT_SUBCOMMAND("drop", &fn, cmd_reflog_drop),
410 + OPT_SUBCOMMAND("expire", &fn, cmd_reflog_expire),
411 OPT_END()
412 };
413