git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Show number of commits being rebased interactively

From
Onno Kortmann <onno@gmx.net>
Date
Dec 7, 2014, 20:56 UTC
Message-ID
<5484BEFD.7060906@gmx.net>
In-Reply-To
<xmqq388tpyls.fsf@gitster.dls.corp.google.com>
Hi,
> These lines above "---" will become the only log message text, which
> is probably not what you intended.  Use "-- >8 --" marker instead
> (that is a perforation line with a pair of scissors on it)?
Thanks, hopefully fixed below.
>> +commitcount=$(git stripspace --strip-comments <"$todo"  | wc -l)
>
> Does this count the number of commits?  I suspect it at least needs
> to filter "x|exec" out.

Very true - after reading this, I learned about the '-x' option to git-rebase -i :-) I changed the patch so it now properly looks for '^pick ' patterns. I hope this should do the trick under all circumstances? In the case of having 'exec' lines interspersed, the $commitcount becomes a lot less useful (no comparison to editor line numbers), though.

Cheers,
Onno
8< 8< 8< 8< 8< 8< 8< 8< 8<
Subject: [PATCH] Show number of commits being rebased interactively

During 'rebase -i', one wrong edit in a long rebase session might inadvertently drop commits. This change shows the total number of commits in the comments below the commit list. After the rebase edit, the number can be quickly compared to the line number of the last commit - by scrolling to the last entry in the rebase TODO list. This gives peace of mind that no commits have been lost in the edit.

Signed-off-by: Onno Kortmann <onno@gmx.net>
---
 git-rebase--interactive.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index b64dd28..b26e5e6 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -1031,9 +1031,13 @@ test -s "$todo" || echo noop >> "$todo"
 test -n "$autosquash" && rearrange_squash "$todo"
 test -n "$cmd" && add_exec_commands "$todo"

+commitcount=$(git stripspace --strip-comments <"$todo"  | \
+	      sane_grep "^pick " | \
+	      wc -l)
+
 cat >>"$todo" <<EOF

-$comment_char Rebase $shortrevisions onto $shortonto
+$comment_char Rebase $shortrevisions onto $shortonto ($commitcount commit(s))
 EOF
 append_todo_help
 git stripspace --comment-lines >>"$todo" <<\EOF
-- 
2.2.0.rc0.18.g1c09766
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “Show number of commits being rebased interactively”
  1. Show number of commits being rebased interactivelyOnno Kortmann, Nov 10, 2014
  2. Junio C HamanoDec 5, 2014
  3. Onno KortmannDec 7, 2014
  4. Junio C HamanoDec 9, 2014
  5. Onno KortmannDec 10, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.