Re: [PATCH v4 05/12] builtin: add new "history" command
- From
Karthik Nayak <karthik.188@gmail.com>
- Date
- Oct 14, 2025, 09:07 UTC
- Message-ID
- <CAOLa=ZQSc0jHv9gK5T06GA_mprknucwCj5H_M2djZ-UWfRMbJQ@mail.gmail.com>
- In-Reply-To
- <20251001-b4-pks-history-builtin-v4-5-8e61ddb86317@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 20 quoted lines
> When rewriting history via git-rebase(1) there are a couple of very > common use cases: > > - The ordering of two commits should be reversed. > > - A commit should be split up into two commits. > > - A commit should be dropped from the history completely. > > - Multiple commits should be squashed into one. > > While these operations are all doable, it often feels needlessly cludgy > to do so by doing an interactive rebase, using the editor to say what > one wants, and then perform the actions. Furthermore, some operations > like splitting up a commit into two are way more involved than that and > require a whole series of commands. > > Add a new "history" command to plug this gap. This command will have > several different subcommands to imperatively rewrite history for common > use cases like the above. These commands will be implemented in
Nit: s/commands/subcommands
> subsequent commits. > > Signed-off-by: Patrick Steinhardt <ps@pks.im>
[snip]
Show 29 quoted lines
> new file mode 100644 > index 0000000000..1537960374 > --- /dev/null > +++ b/Documentation/git-history.adoc > @@ -0,0 +1,45 @@ > +git-history(1) > +============== > + > +NAME > +---- > +git-history - EXPERIMENTAL: Rewrite history of the current branch > + > +SYNOPSIS > +-------- > +[synopsis] > +git history [<options>] > + > +DESCRIPTION > +----------- > + > +Rewrite history by rearranging or modifying specific commits in the > +history. > + > +This command is similar to linkgit:git-rebase[1] and uses the same > +underlying machinery. You should use rebases if you either want to > +reapply a range of commits onto a different base, or interactive rebases > +if you want to edit a range of commits. > + >
The either..or in the last sentence is a bit confusing; as it is not an either between 'want to reapply a range of commit onto a different base' & 'interactive rebases'.
Perhaps we can simply s/either//
Show 22 quoted lines
> +Note that this command does not (yet) work with histories that contain > +merges. You should use linkgit:git-rebase[1] with the `--rebase-merges` > +flag instead. > + > +THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. > + > +COMMANDS > +-------- > + > +This command requires a subcommand. Several subcommands are available to > +rewrite history in different ways: > + > +CONFIGURATION > +------------- > + > +include::includes/cmd-config-section-all.adoc[] > + > +include::config/sequencer.adoc[] > + > +GIT > +--- > +Part of the linkgit:git[1] suite
[snip]
Show 19 quoted lines
> diff --git a/builtin/history.c b/builtin/history.c
> new file mode 100644
> index 0000000000..f6fe32610b
> --- /dev/null
> +++ b/builtin/history.c
> @@ -0,0 +1,22 @@
> +#include "builtin.h"
> +#include "gettext.h"
> +#include "parse-options.h"
> +
> +int cmd_history(int argc,
> + const char **argv,
> + const char *prefix,
> + struct repository *repo UNUSED)
> +{
> + const char * const usage[] = {
> + N_("git history [<options>]"),
> + NULL,
> + };Nit: We have pointer alignment set to 'Right' in our styling guide and also mentioned in our 'Documentation/CodingGuidelines'
When declaring pointers, the star sides with the variable name, i.e. "char *string", not "char* string" or "char * string". This makes it easier to understand code like "char *string, c;".
The rest of the patch looks good!
[snip]