@matheusbsbs / matheus-bagliano / commits / 1eb1e9eea4
Fork 0

commit: allow --amend to reuse message from another commit

After tentatively applying a patch from a contributor, you can get a replacement patch with corrected code and unusable commit log message. In such a case, this sequence ought to give you an editor based on the message in the earlier commit, to let you describe an incremental improvement: git reset --hard HEAD^ ;# discard the earlier one git am <corrected-patch git commit --amend -c HEAD@{1} Unfortunately, --amend insisted reusing the message from the commit being amended, ignoring the -c option. This corrects it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 14, 2007 at 11:57 UTC 1eb1e9eea480059d4fba171e74a4375b8191e3f3
2 files changed +18 -1
builtin-commit.c
+1 -1
@@ -537,7 +537,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
537 die("Option -m cannot be combined with -c/-C/-F.");
538 if (edit_message)
539 use_message = edit_message;
540 - if (amend)
540 + if (amend && !use_message)
541 use_message = "HEAD";
542 if (use_message) {
543 unsigned char sha1[20];
t/t7501-commit.sh
+17
@@ -310,4 +310,21 @@ test_expect_success 'same tree (merge and amend merge)' '
310
311 '
312
313 +test_expect_success 'amend using the message from another commit' '
314 +
315 + git reset --hard &&
316 + test_tick &&
317 + git commit --allow-empty -m "old commit" &&
318 + old=$(git rev-parse --verify HEAD) &&
319 + test_tick &&
320 + git commit --allow-empty -m "new commit" &&
321 + new=$(git rev-parse --verify HEAD) &&
322 + test_tick &&
323 + git commit --allow-empty --amend -C "$old" &&
324 + git show --pretty="format:%ad %s" "$old" >expected &&
325 + git show --pretty="format:%ad %s" HEAD >actual &&
326 + diff -u expected actual
327 +
328 +'
329 +
330 test_done