|
| 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 | +git history reword [<options>] <commit> |
| 13 | +git history split [<options>] <commit> [--] [<pathspec>...] |
| 14 | + |
| 15 | +DESCRIPTION |
| 16 | +----------- |
| 17 | + |
| 18 | +Rewrite history by rearranging or modifying specific commits in the |
| 19 | +history. |
| 20 | + |
| 21 | +This command is similar to linkgit:git-rebase[1] and uses the same |
| 22 | +underlying machinery. You should use rebases if you either want to |
| 23 | +reapply a range of commits onto a different base, or interactive rebases |
| 24 | +if you want to edit a 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 | +THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE. |
| 31 | + |
| 32 | +COMMANDS |
| 33 | +-------- |
| 34 | + |
| 35 | +This command requires a subcommand. Several subcommands are available to |
| 36 | +rewrite history in different ways: |
| 37 | + |
| 38 | +`reword <commit> [--message=<message>]`:: |
| 39 | + Rewrite the commit message of the specified commit. All the other |
| 40 | + details of this commit remain unchanged. If no commit message is |
| 41 | + provided, then this command will spawn an editor with the current |
| 42 | + message of that commit. |
| 43 | + |
| 44 | +`split [--message=<message>] <commit> [--] [<pathspec>...]`:: |
| 45 | + Interactively split up <commit> into two commits by choosing |
| 46 | + hunks introduced by it that will be moved into the new split-out |
| 47 | + commit. These hunks will then be written into a new commit that |
| 48 | + becomes the parent of the previous commit. The original commit |
| 49 | + stays intact, except that its parent will be the newly split-out |
| 50 | + commit. |
| 51 | ++ |
| 52 | +The commit message of the new commit will be asked for by launching the |
| 53 | +configured editor, unless it has been specified with the `-m` option. |
| 54 | +Authorship of the commit will be the same as for the original commit. |
| 55 | ++ |
| 56 | +If passed, _<pathspec>_ can be used to limit which changes shall be split out |
| 57 | +of the original commit. Files not matching any of the pathspecs will remain |
| 58 | +part of the original commit. For more details, see the 'pathspec' entry in |
| 59 | +linkgit:gitglossary[7]. |
| 60 | ++ |
| 61 | +It is invalid to select either all or no hunks, as that would lead to |
| 62 | +one of the commits becoming empty. |
| 63 | + |
| 64 | +CONFIGURATION |
| 65 | +------------- |
| 66 | + |
| 67 | +include::includes/cmd-config-section-all.adoc[] |
| 68 | + |
| 69 | +include::config/sequencer.adoc[] |
| 70 | + |
| 71 | +EXAMPLES |
| 72 | +-------- |
| 73 | + |
| 74 | +Split a commit |
| 75 | +~~~~~~~~~~~~~~ |
| 76 | + |
| 77 | +---------- |
| 78 | +$ git log --stat --oneline |
| 79 | +3f81232 (HEAD -> main) original |
| 80 | + bar | 1 + |
| 81 | + foo | 1 + |
| 82 | + 2 files changed, 2 insertions(+) |
| 83 | +
|
| 84 | +$ git history split HEAD --message="split-out commit" |
| 85 | +diff --git a/bar b/bar |
| 86 | +new file mode 100644 |
| 87 | +index 0000000..5716ca5 |
| 88 | +--- /dev/null |
| 89 | ++++ b/bar |
| 90 | +@@ -0,0 +1 @@ |
| 91 | ++bar |
| 92 | +(1/1) Stage addition [y,n,q,a,d,e,p,?]? y |
| 93 | +
|
| 94 | +diff --git a/foo b/foo |
| 95 | +new file mode 100644 |
| 96 | +index 0000000..257cc56 |
| 97 | +--- /dev/null |
| 98 | ++++ b/foo |
| 99 | +@@ -0,0 +1 @@ |
| 100 | ++foo |
| 101 | +(1/1) Stage addition [y,n,q,a,d,e,p,?]? n |
| 102 | +
|
| 103 | +$ git log --stat --oneline |
| 104 | +7cebe64 (HEAD -> main) original |
| 105 | + foo | 1 + |
| 106 | + 1 file changed, 1 insertion(+) |
| 107 | +d1582f3 split-out commit |
| 108 | + bar | 1 + |
| 109 | + 1 file changed, 1 insertion(+) |
| 110 | +---------- |
| 111 | + |
| 112 | +GIT |
| 113 | +--- |
| 114 | +Part of the linkgit:git[1] suite |
0 commit comments