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

[PATCH] rebase: learn --discard subcommand

From
Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
Date
May 28, 2011, 02:58 UTC
Message-ID
<1306551495-26685-1-git-send-email-martin.von.zweigbergk@gmail.com>

Teach git-rebase the --discard subcommand, which is similar to --abort, but does not move back to the original branch. Suggest this new subcommand to the user where we currently suggest to delete $GIT_DIR/rebase-apply (or rebase-merge).

Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---

A long time ago I said I wished that 'git rebase --abort' would move back to the where HEAD was when the rebase was initiated, instead of moving back to the branch that was about to be rebased (which may be different for "git rebase $upstream $branch"). I think Junio then hinted that he sometimes wished that he could abort rebase without moving to anywhere else at all, which is what this patch implements. I don't feel strongly about this patch, but I would probably also use this subcommand once in a while. However, maybe the greatest value in it is that we don't have to tell users to mess with the .git directory?

I used "rm -r" without -f to match how it is done in --abort, but maybe -f should be used? That is what we recommend to the end-user to use today.

A difference from --abort is that --discard does not clear rerere. Need this be mentioned in the documentation?

I have not been involved in Ramkumar's work on the sequencer to know if and how this might impact it.

 Documentation/git-rebase.txt |    5 ++++-
 git-rebase.sh                |   17 +++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 9a075bc..e841c21 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -13,7 +13,7 @@ SYNOPSIS
 'git rebase' [-i | --interactive] [options] --onto <newbase>
 	--root [<branch>]
 
-'git rebase' --continue | --skip | --abort
+'git rebase' --continue | --skip | --abort | --discard
 
 DESCRIPTION
 -----------
@@ -238,6 +238,9 @@ leave out at most one of A and B, in which case it defaults to HEAD.
 --skip::
 	Restart the rebasing process by skipping the current patch.
 
+--discard::
+	Abort the rebase operation without restoring the original branch.
+
 -m::
 --merge::
 	Use merging strategies to rebase.  When the recursive (default) merge
diff --git a/git-rebase.sh b/git-rebase.sh
index 7a54bfc..befee92 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -32,7 +32,7 @@ OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git rebase [-i] [options] [--onto <newbase>] [<upstream>] [<branch>]
 git rebase [-i] [options] --onto <newbase> --root [<branch>]
-git-rebase [-i] --continue | --abort | --skip
+git-rebase [-i] --continue | --abort | --skip | --discard
 --
  Available options are
 v,verbose!         display a diffstat of what changed upstream
@@ -60,6 +60,7 @@ C=!                passed to 'git apply'
 continue!          continue rebasing process
 abort!             abort rebasing process and restore original branch
 skip!              skip current patch and continue rebasing process
+discard!           abort rebasing process, but do not restore original branch
 "
 . git-sh-setup
 set_reflog_action rebase
@@ -93,7 +94,7 @@ in_progress=
 type=
 # One of {"$GIT_DIR"/rebase-apply, "$GIT_DIR"/rebase-merge}
 state_dir=
-# One of {'', continue, skip, abort}, as parsed from command line
+# One of {'', continue, skip, abort, discard}, as parsed from command line
 action=
 preserve_merges=
 autosquash=
@@ -206,7 +207,7 @@ do
 	--verify)
 		ok_to_skip_pre_rebase=
 		;;
-	--continue|--skip|--abort)
+	--continue|--skip|--abort|--discard)
 		test $total_argc -eq 2 || usage
 		action=${1##--}
 		;;
@@ -340,6 +341,10 @@ abort)
 	rm -r "$state_dir"
 	exit
 	;;
+discard)
+	rm -r "$state_dir"
+	exit
+	;;
 esac
 
 # Make sure no rebase is in progress
@@ -349,9 +354,9 @@ then
 It seems that there is already a '"${state_dir##*/}"' directory, and
 I wonder if you are in the middle of another rebase.  If that is the
 case, please try
-	git rebase (--continue | --abort | --skip)
-If that is not the case, please
-	rm -fr '"$state_dir"'
+	git rebase (--continue | --abort | --skip | --discard)
+If that is not the case, please run
+	git rebase --discard
 and run me again.  I am stopping in case you still have something
 valuable there.'
 fi
-- 
1.7.4.79.gcbe20
Next: Ramkumar Ramachandra
Message 1 of 17 in “rebase: learn --discard subcommand”
  1. rebase: learn --discard subcommandMartin von Zweigbergk, May 28, 2011
  2. Ramkumar RamachandraMay 28, 2011
  3. Martin von ZweigbergkMay 29, 2011
  4. Junio C HamanoMay 28, 2011
  5. Tim MazidMay 28, 2011
  6. Jonathan NiederMay 28, 2011
  7. Martin von ZweigbergkMay 29, 2011
  8. Jakub NarebskiMay 29, 2011
  9. Michael HaggertyMay 30, 2011
  10. Jonathan NiederMay 28, 2011
  11. Tim MazidMay 29, 2011
  12. Martin von ZweigbergkMay 29, 2011
  13. Jonathan NiederMay 29, 2011
  14. Michael HaggertyMay 30, 2011
  15. Tim MazidMay 30, 2011
  16. Michael HaggertyMay 30, 2011
  17. Miles BaderMay 30, 2011

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.