Signed-off-by: Pieter Praet <[email protected]>
---
magit.el | 35 ++++++++++++++++++++++++++++++++++-
magit.texi | 7 ++++---
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/magit.el b/magit.el
index 4a784ca..0224c60 100644
--- a/magit.el
+++ b/magit.el
@@ -240,6 +240,29 @@ The function is given one argument, the status buffer."
(function-item pop-to-buffer)
(function :tag "Other")))
+(defcustom magit-rewrite-inclusive t
+ "Whether magit includes the selected base commit in a rewrite operation.
+
+t means both the selected commit as well as any subsequent
+commits will be rewritten. This is magit's default behaviour,
+equivalent to 'git rebase -i ${REV}~1'
+
+ A'---B'---C'---D'
+ ^
+
+nil means the selected commit will be literally used as 'base',
+so only subsequent commits will be rewritten. This is consistent
+with git-rebase, equivalent to 'git rebase -i ${REV}', yet more
+cumbersome to use from the status buffer.
+
+ A---B'---C'---D'
+ ^
+"
+ :group 'magit
+ :type '(choice (const :tag "Always" t)
+ (const :tag "Never" nil)
+ (const :tag "Ask" ask)))
+
(defgroup magit-faces nil
"Customize the appearance of Magit"
:prefix "magit-"
@@ -3547,7 +3570,17 @@ Uncomitted changes in both working tree and staging area
are lost.
(or (not (magit-read-rewrite-info))
(error "Rewrite in progress"))
(let* ((orig (magit-rev-parse "HEAD"))
- (base from)
+ (base
+ (if
+ (or
+ (eq magit-rewrite-inclusive t)
+ (and
+ (eq magit-rewrite-inclusive 'ask)
+ (y-or-n-p "Include selected revision in rewrite? ")))
+ (or
+ (car (magit-commit-parents from))
+ (error "Can't rewrite a parentless commit."))
+ from))
(pending (magit-git-lines "rev-list" (concat base ".."))))
(magit-write-rewrite-info `((orig ,orig)
(pending ,@(mapcar #'list pending))))
diff --git a/magit.texi b/magit.texi
index 4c123a4..423f298 100644
--- a/magit.texi
+++ b/magit.texi
@@ -655,9 +655,10 @@ associated with rewriting. These commands all start with
the @kbd{r}
prefix key.
Typing @kbd{r b} will start a rewrite operation. You will be prompted
-for a @emph{base} commit, and all commits between the current head and
-this commit are put in a list of @emph{Pending commits}. The current
-head will then be reset to the base commit.
+for a @emph{base} commit. This commit and all subsequent commits up
+until the current head are then put in a list of @emph{Pending
+commits}, after which the current head will be reset to the
+@emph{parent} of the base commit.
You would then typically use @kbd{a} and @kbd{A} to cherry pick
commits from the list of pending commits in the desired order, until
--
1.7.1