Skip to content

Commit

Permalink
rebase --preserve-merges: keep all merge commits including empty ones
Browse files Browse the repository at this point in the history
Since 90e1818  (git-rebase: add keep_empty flag, 2012-04-20)
'git rebase --preserve-merges' fails to preserve empty merge commits
unless --keep-empty is also specified.  Merge commits should be
preserved in order to preserve the structure of the rebased graph,
even if the merge commit does not introduce changes to the parent.

Teach rebase not to drop merge commits only because they are empty.

A special case which is not handled by this change is for a merge commit
whose parents are now the same commit because all the previous different
parents have been dropped as a result of this rebase or some previous
operation.

Signed-off-by: Phil Hord <hordp@cisco.com>
Acked-by: Neil Horman <nhorman@tuxdriver.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Phil Hord authored and Junio C Hamano committed Jan 14, 2013
1 parent 1692579 commit 9869778
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ is_empty_commit() {
test "$tree" = "$ptree"
}

is_merge_commit()
{
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
}

# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
# GIT_AUTHOR_DATE exported from the current environment.
do_with_author () {
Expand Down Expand Up @@ -796,7 +801,7 @@ git rev-list $merges_option --pretty=oneline --abbrev-commit \
while read -r shortsha1 rest
do

if test -z "$keep_empty" && is_empty_commit $shortsha1
if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
then
comment_out="# "
else
Expand Down

0 comments on commit 9869778

Please sign in to comment.