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

[PATCH 3/5] Add --skip-redundant-commits option to rebase

From
David Greene <greened@obbligato.org>
Date
Jan 11, 2016, 05:00 UTC
Message-ID
<1452488421-26823-4-git-send-email-greened@obbligato.org>
In-Reply-To
<1452488421-26823-1-git-send-email-greened@obbligato.org>
From: "David A. Greene" <greened@obbligato.org>

Teach rebase to ignore redundant commits if told. Since rebase normally automatically skips redundant commits, this only applies when it has to use cherry-pick to do its work. In that case, pass the --skip-redundant-commits flag to cherry-pick.

This allows scripted use of rebase with options like --preserve-merges that tend to invoke cherry-pick.

Signed-off-by: David A. Greene <greened@obbligato.org>
---
 git-rebase--interactive.sh | 14 ++++++++++++--
 git-rebase.sh              |  5 +++++
 2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index c0cfe88..5891ff5 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -269,9 +269,14 @@ pick_one () {
 
 	test -d "$rewritten" &&
 		pick_one_preserving_merges "$@" && return
+	redundant_args=
+	if test -n "$skip_redundant_commits"
+	then
+		redundant_args="--skip-redundant-commits"
+	fi
 	output eval git cherry-pick \
 			${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
-			"$strategy_args" $empty_args $ff "$@"
+			"$strategy_args" $empty_args $redundant_args $ff "$@"
 
 	# If cherry-pick dies it leaves the to-be-picked commit unrecorded. Reschedule
 	# previous task so this commit is not lost.
@@ -389,9 +394,14 @@ pick_one_preserving_merges () {
 			echo "$sha1 $(git rev-parse HEAD^0)" >> "$rewritten_list"
 			;;
 		*)
+			redundant_args=
+			if test -n "$skip_redundant_commits"
+			then
+				redundant_args="--skip-redundant-commits"
+			fi
 			output eval git cherry-pick \
 				${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")} \
-				"$strategy_args" "$@" ||
+				"$strategy_args" $redundant_args "$@" ||
 				die_with_patch $sha1 "Could not pick $sha1"
 			;;
 		esac
diff --git a/git-rebase.sh b/git-rebase.sh
index af7ba5f..420a54f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -24,6 +24,7 @@ m,merge!           use merging strategies to rebase
 i,interactive!     let the user edit the list of commits to rebase
 x,exec=!           add exec lines after each commit of the editable list
 k,keep-empty	   preserve empty commits during rebase
+skip-redundant-commits ignore redundant commits during rebase
 f,force-rebase!    force rebase even if branch is up to date
 X,strategy-option=! pass the argument through to the merge strategy
 stat!              display a diffstat of what changed upstream
@@ -86,6 +87,7 @@ action=
 preserve_merges=
 autosquash=
 keep_empty=
+skip_redundant_commits=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
 gpg_sign_opt=
 
@@ -255,6 +257,9 @@ do
 	--keep-empty)
 		keep_empty=yes
 		;;
+	--skip-redundant-commits)
+		skip_redundant_commits=yes
+		;;
 	--preserve-merges)
 		preserve_merges=t
 		test -z "$interactive_rebase" && interactive_rebase=implied
-- 
2.6.1
Previous: David GreeneNext: David Greene
Message 6 of 9 in “Teach cherry-pick and rebase to ignore redundant commits”
  1. Teach cherry-pick and rebase to ignore redundant commitsDavid Greene, Jan 11, 2016
  2. 1/5 Teach cherry-pick to skip redundant commits if askedDavid Greene, Jan 11, 2016
  3. Junio C HamanoJan 11, 2016
  4. David A. GreeneJan 12, 2016
  5. 2/5 Add test for cherry-pick --skip-redundant-commitsDavid Greene, Jan 11, 2016
  6. 3/5 Add --skip-redundant-commits option to rebaseDavid Greene, Jan 11, 2016
  7. 4/5 Add test for redundant rebaseDavid Greene, Jan 11, 2016
  8. 5/5 Add test for rebase with merges amd redundant commitsDavid Greene, Jan 11, 2016
  9. Eric SunshineJan 11, 2016

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.