Skip to content

Commit 85ae602

Browse files
pks-tgitster
authored andcommitted
builtin: add new "history" command
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 kludgey 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 subcommands will be implemented in subsequent commits. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b00f91d commit 85ae602

File tree

11 files changed

+91
-0
lines changed

11 files changed

+91
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
/git-grep
8080
/git-hash-object
8181
/git-help
82+
/git-history
8283
/git-hook
8384
/git-http-backend
8485
/git-http-fetch

Documentation/git-history.adoc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
git-history(1)
2+
==============
3+
4+
NAME
5+
----
6+
git-history - EXPERIMENTAL: Rewrite history of the current branch
7+
8+
SYNOPSIS
9+
--------
10+
[synopsis]
11+
git history [<options>]
12+
13+
DESCRIPTION
14+
-----------
15+
16+
Rewrite history by rearranging or modifying specific commits in the
17+
history.
18+
19+
THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
20+
21+
This command is similar to linkgit:git-rebase[1] and uses the same
22+
underlying machinery. You should use rebases if you want to reapply a range of
23+
commits onto a different base, or interactive rebases if you want to edit a
24+
range of commits.
25+
26+
Note that this command does not (yet) work with histories that contain
27+
merges. You should use linkgit:git-rebase[1] with the `--rebase-merges`
28+
flag instead.
29+
30+
COMMANDS
31+
--------
32+
33+
Several commands are available to rewrite history in different ways:
34+
35+
CONFIGURATION
36+
-------------
37+
38+
include::includes/cmd-config-section-all.adoc[]
39+
40+
include::config/sequencer.adoc[]
41+
42+
GIT
43+
---
44+
Part of the linkgit:git[1] suite

Documentation/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ manpages = {
6464
'git-gui.adoc' : 1,
6565
'git-hash-object.adoc' : 1,
6666
'git-help.adoc' : 1,
67+
'git-history.adoc' : 1,
6768
'git-hook.adoc' : 1,
6869
'git-http-backend.adoc' : 1,
6970
'git-http-fetch.adoc' : 1,

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ BUILTIN_OBJS += builtin/get-tar-commit-id.o
13951395
BUILTIN_OBJS += builtin/grep.o
13961396
BUILTIN_OBJS += builtin/hash-object.o
13971397
BUILTIN_OBJS += builtin/help.o
1398+
BUILTIN_OBJS += builtin/history.o
13981399
BUILTIN_OBJS += builtin/hook.o
13991400
BUILTIN_OBJS += builtin/index-pack.o
14001401
BUILTIN_OBJS += builtin/init-db.o

builtin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix, struc
172172
int cmd_grep(int argc, const char **argv, const char *prefix, struct repository *repo);
173173
int cmd_hash_object(int argc, const char **argv, const char *prefix, struct repository *repo);
174174
int cmd_help(int argc, const char **argv, const char *prefix, struct repository *repo);
175+
int cmd_history(int argc, const char **argv, const char *prefix, struct repository *repo);
175176
int cmd_hook(int argc, const char **argv, const char *prefix, struct repository *repo);
176177
int cmd_index_pack(int argc, const char **argv, const char *prefix, struct repository *repo);
177178
int cmd_init_db(int argc, const char **argv, const char *prefix, struct repository *repo);

builtin/history.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "builtin.h"
2+
#include "gettext.h"
3+
#include "parse-options.h"
4+
5+
int cmd_history(int argc,
6+
const char **argv,
7+
const char *prefix,
8+
struct repository *repo UNUSED)
9+
{
10+
const char * const usage[] = {
11+
N_("git history [<options>]"),
12+
NULL,
13+
};
14+
struct option options[] = {
15+
OPT_END(),
16+
};
17+
18+
argc = parse_options(argc, argv, prefix, options, usage, 0);
19+
if (argc)
20+
usagef("unrecognized argument: %s", argv[0]);
21+
return 0;
22+
}

command-list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ git-grep mainporcelain info
115115
git-gui mainporcelain
116116
git-hash-object plumbingmanipulators
117117
git-help ancillaryinterrogators complete
118+
git-history mainporcelain history
118119
git-hook purehelpers
119120
git-http-backend synchingrepositories
120121
git-http-fetch synchelpers

git.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ static struct cmd_struct commands[] = {
586586
{ "grep", cmd_grep, RUN_SETUP_GENTLY },
587587
{ "hash-object", cmd_hash_object },
588588
{ "help", cmd_help },
589+
{ "history", cmd_history, RUN_SETUP },
589590
{ "hook", cmd_hook, RUN_SETUP },
590591
{ "index-pack", cmd_index_pack, RUN_SETUP_GENTLY | NO_PARSEOPT },
591592
{ "init", cmd_init_db },

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ builtin_sources = [
604604
'builtin/grep.c',
605605
'builtin/hash-object.c',
606606
'builtin/help.c',
607+
'builtin/history.c',
607608
'builtin/hook.c',
608609
'builtin/index-pack.c',
609610
'builtin/init-db.c',

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ integration_tests = [
384384
't3436-rebase-more-options.sh',
385385
't3437-rebase-fixup-options.sh',
386386
't3438-rebase-broken-files.sh',
387+
't3450-history.sh',
387388
't3500-cherry.sh',
388389
't3501-revert-cherry-pick.sh',
389390
't3502-cherry-pick-merge.sh',

0 commit comments

Comments
 (0)