]> git.ipfire.org Git - thirdparty/git.git/commit
cherry-pick: add `--empty` for more robust redundant commit handling
authorBrian Lyles <brianmlyles@gmail.com>
Mon, 25 Mar 2024 23:16:54 +0000 (18:16 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Mar 2024 23:45:41 +0000 (16:45 -0700)
commitec79d763de617905bd9275de0b5941a160d6159b
treee31824938c4744a2ea1c077ac4e93f5ec2fbf40c
parentbd2f9fd025e3aa2926f249e9c24f1f648e89d997
cherry-pick: add `--empty` for more robust redundant commit handling

As with git-rebase(1) and git-am(1), git-cherry-pick(1) can result in a
commit being made redundant if the content from the picked commit is
already present in the target history. However, git-cherry-pick(1) does
not have the same options available that git-rebase(1) and git-am(1) have.

There are three things that can be done with these redundant commits:
drop them, keep them, or have the cherry-pick stop and wait for the user
to take an action. git-rebase(1) has the `--empty` option added in commit
e98c4269c8 (rebase (interactive-backend): fix handling of commits that
become empty, 2020-02-15), which handles all three of these scenarios.
Similarly, git-am(1) got its own `--empty` in 7c096b8d61 (am: support
--empty=<option> to handle empty patches, 2021-12-09).

git-cherry-pick(1), on the other hand, only supports two of the three
possiblities: Keep the redundant commits via `--keep-redundant-commits`,
or have the cherry-pick fail by not specifying that option. There is no
way to automatically drop redundant commits.

In order to bring git-cherry-pick(1) more in-line with git-rebase(1) and
git-am(1), this commit adds an `--empty` option to git-cherry-pick(1). It
has the same three options (keep, drop, and stop), and largely behaves
the same. The notable difference is that for git-cherry-pick(1), the
default will be `stop`, which maintains the current behavior when the
option is not specified.

Like the existing `--keep-redundant-commits`, `--empty=keep` will imply
`--allow-empty`.

The `--keep-redundant-commits` option will be documented as a deprecated
synonym of `--empty=keep`, and will be supported for backwards
compatibility for the time being.

Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-cherry-pick.txt
builtin/revert.c
sequencer.c
t/t3505-cherry-pick-empty.sh
t/t3510-cherry-pick-sequence.sh