Search code examples
gitgit-rebase

Git de-selects a commit be default in interactive rebase


When I run git interactive rebase on a branch git for some reason decides that I don't want the 9df79 commit below:

enter image description here

How is that possible?

I have NOT commented out that line/commit myself.


Solution

  • "Empty" commits are dropped by default (see the comment on line 25 in your pasted-in image), via this bit of code in the setup for an interactive rebase:

    git rev-list $merges_option --pretty=oneline --reverse --left-right --topo-order \
            $revisions ${restrict_revision+^$restrict_revision} | \
            sed -n "s/^>//p" |
    while read -r sha1 rest
    do
    
            if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
            then
                    comment_out="$comment_char "
            else
                    comment_out=
            fi
    

    The $keep_empty variable is set based on the --keep-empty (or -k) flag you supply on the command line, so without it non-empty non-merge commits come out as # pick ....

    (An "empty" commit is one whose source tree is identical to its parent's.)