einpoklum
einpoklum

Reputation: 131544

How can I see more log lines in the git-rebase TODO editor session?

When you git rebase -i 1234abcd, you get an editor session with the 'TODO' list for the rebase: What needs to be done for each relevant changeset.

Now, by default, we see one line per commit - the first line of the commit message. However, some of us write multi-line commit messages in which the first line doesn't say much.

Is it possible to somehow get git to print content from additional lines, in the TODO editor? I don't mind the exact format, I just need to distinguish the different commits to know what I'm doing.

Upvotes: 1

Views: 473

Answers (2)

Marco Luzzara
Marco Luzzara

Reputation: 6036

Unfortunately, I do not think it is possible. The only way you can customize the rebase output is through rebase.instructionFormat configuration, like this:

git config rebase.instructionFormat "..."

I tried with the option %B to return the subject with the body too, but the rebase operation fails with the following error:

error: invalid line 5: second line
error: invalid line 7: third line
error: invalid line 8: forth line
BUG: builtin/rebase.c:353: unusable todo list
Aborted (core dumped)

it seems like git considers the lines after the first one as executable code. I checked on the git log documentation, but among the --format options I did not see anything that could replace the line feed with something else, or simply ignore it.

At this point, you could clone your repo, run git filter-branch to replace line feeds with spaces for example, and eventually run git rebase -i.

git filter-branch --msg-filter "xargs echo"

The interactive rebase does not consider the "third column", basically what you choose to log for a certain commit, so at the end you could copy and paste the output of the interactive rebase on the second repo (the one you filter-branched) inside the editor of your main repo.

Anyway, I just found a question similar to yours.


EDIT: if you want another tool to take care of formatting the new commit message you can always create a script, like this one to replace line feed with \n

#!/bin/bash
cat | sed ':a;N;$!ba;s/\n/\\n/g'

and call it inside --msg-filter option

git filter-branch --msg-filter "cat | $(pwd)/script.sh"

EDIT: I almost forgot that filter-branch recreates each commit that matches with the filter specified, so, before editing you should replace the commits column of the interactive rebase output in the cloned repo with the real commits in the main repo. It is getting more tedious than I imagined. Let's go back to simple things: we can simulate an interactive rebase without actually calling it. The script can be improved but I think the direction is the right one:

#!/bin/bash
for commit in $(git rev-list $1..HEAD | tac)
do
    git log -n 1 $commit --format="pick %h %B" | xargs echo
done;

you call it like this

./script HEAD~3

and you obtain the interactive rebase output (kind of, without comments)

pick 483ac92 first commit
pick bb739b7 second commit
pick 59f2bf0 very long commit with multiline

Upvotes: 3

hakre
hakre

Reputation: 197767

However, some of us write multi-line commit messages in which the first line doesn't say much.

Next to the line there is the abbreviated revision hash. Given you're using vim or compatible just enter command: exclamation mark git space show space hash and hit enter:

:!git show 1234abcd

You will then see the subject line of the commit which does not say much to you, then the commit message.

In case the body of the commit message is not enough this will also display the paths that are changed and the diff of the changes.

If you're using a different editor, check the documentation on how to execute a shell command while in the editor. While rebasing interactively the working directory is the root of the working tree of the git repository current interactive rebase was initiated from.

Other tooling exists, for example you may want to open gitk in another window to guide your interactive rebase. Press g to enter a revision and jump to it.

See also A Note About Git Commit Messages (by Tim Pope; Apr 2008).

Hint: Consider to use the interactive rebase to reword those commit messages their subject lines do not say much to you until they do first.

Upvotes: 1

Related Questions