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

[PATCH 1/4] Rewrite rebase to use git-format-patch piped to git-am.

From
Junio C Hamano <junkio@cox.net>
Date
Nov 15, 2005, 23:33 UTC
Message-ID
<7virutfpvc.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7voe4lfpxm.fsf@assigned-by-dhcp.cox.net>

This does not handle binary files yet, but a patch or two to git-apply should solve that problem.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 git-rebase.sh |   71 ++++++++++++---------------------------------------------
 1 files changed, 15 insertions(+), 56 deletions(-)

applies-to: efad0bc70473bdc02b8ac6a5e5f001519f1d5dfa d64a7b926edfcebf9f5b116fedebd365e5c206f1

diff --git a/git-rebase.sh b/git-rebase.sh
index fa95009..56196e7 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -5,65 +5,24 @@
 
 . git-sh-setup || die "Not a git archive."
 
-usage="usage: $0 "'<upstream> [<head>]
-
-Uses output from git-cherry to rebase local commits to the new head of
-upstream tree.'
-
-case "$#,$1" in
-1,*..*)
-    upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
-    set x "$upstream" "$ours"
-    shift ;;
-esac
+# The other head is given
+other=$(git-rev-parse --verify "$1^0") || exit
 
+# The tree must be really really clean.
 git-update-index --refresh || exit
+diff=$(git-diff-index --cached --name-status -r HEAD)
+case "$different" in
+?*)	echo "$diff"
+	exit 1
+	;;
+esac
 
+# If the branch to rebase is given, first switch to it.
 case "$#" in
-1) ours_symbolic=HEAD ;;
-2) ours_symbolic="$2" ;;
-*) die "$usage" ;;
+2)
+	git-checkout "$2" || exit
 esac
 
-upstream=`git-rev-parse --verify "$1"` &&
-ours=`git-rev-parse --verify "$ours_symbolic"` || exit
-different1=$(git-diff-index --name-only --cached "$ours") &&
-different2=$(git-diff-index --name-only "$ours") &&
-test "$different1$different2" = "" ||
-die "Your working tree does not match $ours_symbolic."
-
-git-read-tree -m -u $ours $upstream &&
-new_head=$(git-rev-parse --verify "$upstream^0") &&
-git-update-ref HEAD "$new_head" || exit
-
-tmp=.rebase-tmp$$
-fail=$tmp-fail
-trap "rm -rf $tmp-*" 1 2 3 15
-
->$fail
-
-git-cherry -v $upstream $ours |
-while read sign commit msg
-do
-	case "$sign" in
-	-)
-		echo >&2 "* Already applied: $msg"
-		continue ;;
-	esac
-	echo >&2 "* Applying: $msg"
-	S=$(git-rev-parse --verify HEAD) &&
-	git-cherry-pick --replay $commit || {
-		echo >&2 "* Not applying the patch and continuing."
-		echo $commit >>$fail
-		git-reset --hard $S
-	}
-done
-if test -s $fail
-then
-	echo >&2 Some commits could not be rebased, check by hand:
-	cat >&2 $fail
-	echo >&2 "(the same list of commits are found in $tmp)"
-	exit 1
-else
-	rm -f $fail
-fi
+# Rewind the head to "$other"
+git-reset --hard "$other"
+git-format-patch -k --stdout "$other" ORIG_HEAD | git am -3 -k
---
0.99.9.GIT
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 8 in “reworking git-rebase”
  1. 0/4 reworking git-rebaseJunio C Hamano, Nov 15, 2005
  2. 1/4 Rewrite rebase to use git-format-patch piped to git-am.Junio C Hamano, Nov 15, 2005
  3. 2/4 apply: allow-binary-replacement.Junio C Hamano, Nov 15, 2005
  4. 3/4 diff: --full-indexJunio C Hamano, Nov 15, 2005
  5. 4/4 rebase: make it usable for binary files as well.Junio C Hamano, Nov 15, 2005
  6. git-am: --resolved.Junio C Hamano, Nov 16, 2005
  7. Sven VerdoolaegeNov 17, 2005
  8. Junio C HamanoNov 17, 2005

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.