Home Explore Blog CI



git

16th chunk of `Documentation/git-rebase.adoc`
30cf1fb12dbed4b128a862a87868bf3422f2647dcef38e3c0000000100000ebd
 # Merge 'report-a-bug'
------------

In contrast to a regular interactive rebase, there are `label`, `reset`
and `merge` commands in addition to `pick` ones.

The `label` command associates a label with the current HEAD when that
command is executed. These labels are created as worktree-local refs
(`refs/rewritten/<label>`) that will be deleted when the rebase
finishes. That way, rebase operations in multiple worktrees linked to
the same repository do not interfere with one another. If the `label`
command fails, it is rescheduled immediately, with a helpful message how
to proceed.

The `reset` command resets the HEAD, index and worktree to the specified
revision. It is similar to an `exec git reset --hard <label>`, but
refuses to overwrite untracked files. If the `reset` command fails, it is
rescheduled immediately, with a helpful message how to edit the todo list
(this typically happens when a `reset` command was inserted into the todo
list manually and contains a typo).

The `merge` command will merge the specified revision(s) into whatever
is HEAD at that time. With `-C <original-commit>`, the commit message of
the specified merge commit will be used. When the `-C` is changed to
a lower-case `-c`, the message will be opened in an editor after a
successful merge so that the user can edit the message.

If a `merge` command fails for any reason other than merge conflicts (i.e.
when the merge operation did not even start), it is rescheduled immediately.

By default, the `merge` command will use the `ort` merge strategy for
regular merges, and `octopus` for octopus merges.  One can specify a
default strategy for all merges using the `--strategy` argument when
invoking rebase, or can override specific merges in the interactive
list of commands by using an `exec` command to call `git merge`
explicitly with a `--strategy` argument.  Note that when calling `git
merge` explicitly like this, you can make use of the fact that the
labels are worktree-local refs (the ref `refs/rewritten/onto` would
correspond to the label `onto`, for example) in order to refer to the
branches you want to merge.

Note: the first command (`label onto`) labels the revision onto which
the commits are rebased; The name `onto` is just a convention, as a nod
to the `--onto` option.

It is also possible to introduce completely new merge commits from scratch
by adding a command of the form `merge <merge-head>`. This form will
generate a tentative commit message and always open an editor to let the
user edit it. This can be useful e.g. when a topic branch turns out to
address more than a single concern and wants to be split into two or
even more topic branches. Consider this todo list:

------------
pick 192837 Switch from GNU Makefiles to CMake
pick 5a6c7e Document the switch to CMake
pick 918273 Fix detection of OpenSSL in CMake
pick afbecd http: add support for TLS v1.3
pick fdbaec Fix detection of cURL in CMake on Windows
------------

The one commit in this list that is not related to CMake may very well
have been motivated by working on fixing all those bugs introduced by
switching to CMake, but it addresses a different concern. To split this
branch into two topic branches, the todo list could be edited like this:

------------
label onto

pick afbecd http: add support for TLS v1.3
label tlsv1.3

reset onto
pick 192837 Switch from GNU Makefiles to CMake
pick 918273 Fix detection of OpenSSL in CMake
pick fdbaec Fix detection of cURL in CMake on Windows
pick 5a6c7e Document the switch to CMake
label cmake

reset onto
merge tlsv1.3
merge cmake
------------

CONFIGURATION
-------------

include::includes/cmd-config-section-all.adoc[]

include::config/rebase.adoc[]
include::config/sequencer.adoc[]

GIT
---
Part of the linkgit:git[1] suite

Title: Advanced Rebasing with Label, Reset, and Merge Commands
Summary
This section describes the `label`, `reset`, and `merge` commands used in interactive rebasing, including how they work, their options, and use cases, such as preserving branch structure, introducing new merge commits, and splitting topic branches, as well as configuration options for rebasing and sequencer behavior.