Commit
d692305326bf24ded5185f1c76fa82b93731db01
commit: allow a partial commit when a rebase pick becomes empty
For years, we disallowed partial commits during merges or cherry-picks. In commit 430b75f7209c (commit: give correct advice for empty commit during a rebase, 2019-12-06) it was noted that the "cannot do a partial commit during a cherry-pick" message was also printed when rebasing a commit that became empty, and rather than drop the check in that case, that commit opted to make the message print the actual operation that was in progress. Since a commit that has become empty comes without conflicts, a new partial commit poses no problems; remove the error in that case. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren <newren@gmail.com> · 2026-09-01 22:24 UTC · committed by Junio C Hamano
2 files changed,
+2
−5
modified builtin/commit.c
| @@ -520,8 +520,6 @@ static const char *prepare_index(const char **argv, const char *prefix, | |||
| 520 | 520 | die(_("cannot do a partial commit during a merge.")); | |
| 521 | 521 | else if (is_from_cherry_pick(whence)) | |
| 522 | 522 | die(_("cannot do a partial commit during a cherry-pick.")); | |
| 523 | - | else if (is_from_rebase_now_empty(whence)) | |
| 524 | - | die(_("cannot do a partial commit during a rebase.")); | |
| 525 | 523 | } | |
| 526 | 524 | ||
| 527 | 525 | if (list_paths(&partial, !current_head ? NULL : "HEAD", &pathspec)) | |
modified t/t3404-rebase-interactive.sh
| @@ -1829,7 +1829,7 @@ test_expect_success 'post-commit hook is called' ' | |||
| 1829 | 1829 | test_cmp expect actual | |
| 1830 | 1830 | ' | |
| 1831 | 1831 | ||
| 1832 | - | test_expect_success 'correct error message for partial commit after empty pick' ' | |
| 1832 | + | test_expect_success 'partial commit is allowed when a rebase pick becomes empty' ' | |
| 1833 | 1833 | test_when_finished "git rebase --abort" && | |
| 1834 | 1834 | ( | |
| 1835 | 1835 | set_fake_editor && | |
| @@ -1838,8 +1838,7 @@ test_expect_success 'correct error message for partial commit after empty pick' | |||
| 1838 | 1838 | test_must_fail git rebase -i A D | |
| 1839 | 1839 | ) && | |
| 1840 | 1840 | echo x >file1 && | |
| 1841 | - | test_must_fail git commit file1 2>err && | |
| 1842 | - | test_grep "cannot do a partial commit during a rebase." err | |
| 1841 | + | git commit file1 | |
| 1843 | 1842 | ' | |
| 1844 | 1843 | ||
| 1845 | 1844 | test_expect_success 'correct error message for commit --amend after empty pick' ' | |