Skip to content

Commit 9869778

Browse files
phordgitster
authored andcommitted
rebase --preserve-merges: keep all merge commits including empty ones
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 <[email protected]> Acked-by: Neil Horman <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1692579 commit 9869778

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

git-rebase--interactive.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ is_empty_commit() {
175175
test "$tree" = "$ptree"
176176
}
177177

178+
is_merge_commit()
179+
{
180+
git rev-parse --verify --quiet "$1"^2 >/dev/null 2>&1
181+
}
182+
178183
# Run command with GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
179184
# GIT_AUTHOR_DATE exported from the current environment.
180185
do_with_author () {
@@ -796,7 +801,7 @@ git rev-list $merges_option --pretty=oneline --abbrev-commit \
796801
while read -r shortsha1 rest
797802
do
798803

799-
if test -z "$keep_empty" && is_empty_commit $shortsha1
804+
if test -z "$keep_empty" && is_empty_commit $shortsha1 && ! is_merge_commit $shortsha1
800805
then
801806
comment_out="# "
802807
else

0 commit comments

Comments
 (0)