Skip to content

Commit 06cd5a1

Browse files
committed
Merge branch 'nd/rebase-forget'
"git rebase" learned "--quit" option, which allows a user to remove the metadata left by an earlier "git rebase" that was manually aborted without using "git rebase --abort". * nd/rebase-forget: rebase: add --quit to cleanup rebase, leave everything else untouched
2 parents f008159 + 9512177 commit 06cd5a1

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

Documentation/git-rebase.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
[<upstream> [<branch>]]
1313
'git rebase' [-i | --interactive] [options] [--exec <cmd>] [--onto <newbase>]
1414
--root [<branch>]
15-
'git rebase' --continue | --skip | --abort | --edit-todo
15+
'git rebase' --continue | --skip | --abort | --quit | --edit-todo
1616

1717
DESCRIPTION
1818
-----------
@@ -252,6 +252,11 @@ leave out at most one of A and B, in which case it defaults to HEAD.
252252
will be reset to where it was when the rebase operation was
253253
started.
254254

255+
--quit::
256+
Abort the rebase operation but HEAD is not reset back to the
257+
original branch. The index and working tree are also left
258+
unchanged as a result.
259+
255260
--keep-empty::
256261
Keep the commits that do not change anything from its
257262
parents in the result.

contrib/completion/git-completion.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,10 +1734,10 @@ _git_rebase ()
17341734
{
17351735
local dir="$(__gitdir)"
17361736
if [ -f "$dir"/rebase-merge/interactive ]; then
1737-
__gitcomp "--continue --skip --abort --edit-todo"
1737+
__gitcomp "--continue --skip --abort --quit --edit-todo"
17381738
return
17391739
elif [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
1740-
__gitcomp "--continue --skip --abort"
1740+
__gitcomp "--continue --skip --abort --quit"
17411741
return
17421742
fi
17431743
__git_complete_strategy && return

git-rebase.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ continue! continue
4343
abort! abort and check out the original branch
4444
skip! skip current patch and continue
4545
edit-todo! edit the todo list during an interactive rebase
46+
quit! abort but keep HEAD where it is
4647
"
4748
. git-sh-setup
4849
set_reflog_action rebase
@@ -241,7 +242,7 @@ do
241242
--verify)
242243
ok_to_skip_pre_rebase=
243244
;;
244-
--continue|--skip|--abort|--edit-todo)
245+
--continue|--skip|--abort|--quit|--edit-todo)
245246
test $total_argc -eq 2 || usage
246247
action=${1##--}
247248
;;
@@ -399,6 +400,9 @@ abort)
399400
finish_rebase
400401
exit
401402
;;
403+
quit)
404+
exec rm -rf "$state_dir"
405+
;;
402406
edit-todo)
403407
run_specific_rebase
404408
;;

t/t3407-rebase-abort.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,28 @@ testrebase() {
9999
testrebase "" .git/rebase-apply
100100
testrebase " --merge" .git/rebase-merge
101101

102+
test_expect_success 'rebase --quit' '
103+
cd "$work_dir" &&
104+
# Clean up the state from the previous one
105+
git reset --hard pre-rebase &&
106+
test_must_fail git rebase master &&
107+
test_path_is_dir .git/rebase-apply &&
108+
head_before=$(git rev-parse HEAD) &&
109+
git rebase --quit &&
110+
test $(git rev-parse HEAD) = $head_before &&
111+
test ! -d .git/rebase-apply
112+
'
113+
114+
test_expect_success 'rebase --merge --quit' '
115+
cd "$work_dir" &&
116+
# Clean up the state from the previous one
117+
git reset --hard pre-rebase &&
118+
test_must_fail git rebase --merge master &&
119+
test_path_is_dir .git/rebase-merge &&
120+
head_before=$(git rev-parse HEAD) &&
121+
git rebase --quit &&
122+
test $(git rev-parse HEAD) = $head_before &&
123+
test ! -d .git/rebase-merge
124+
'
125+
102126
test_done

0 commit comments

Comments
 (0)