Skip to content

Commit 3b21a43

Browse files
peffgitster
authored andcommitted
rebase: use explicit "--" with checkout
In the case of a ref/pathname conflict, checkout will already do the right thing and checkout the ref. However, for a non-existant ref, this has two advantages: 1. If a file with that pathname exists, rebase will refresh the file from the index and then rebase the current branch instead of producing an error. 2. If no such file exists, the error message using an explicit "--" is better: # before $ git rebase -i origin bogus error: pathspec 'bogus' did not match any file(s) known to git. Could not checkout bogus # after $ git rebase -i origin bogus fatal: invalid reference: bogus Could not checkout bogus The problems seem to be trigger-able only through "git rebase -i", as regular git-rebase checks the validity of the branch parameter as a ref very early on. However, it doesn't hurt to be defensive. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b312b41 commit 3b21a43

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

git-rebase--interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ first and then run 'git rebase --continue' again."
870870

871871
if test ! -z "$1"
872872
then
873-
output git checkout "$1" ||
873+
output git checkout "$1" -- ||
874874
die "Could not checkout $1"
875875
fi
876876

git-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ then
522522
if test -z "$force_rebase"
523523
then
524524
# Lazily switch to the target branch if needed...
525-
test -z "$switch_to" || git checkout "$switch_to"
525+
test -z "$switch_to" || git checkout "$switch_to" --
526526
say "Current branch $branch_name is up to date."
527527
exit 0
528528
else

0 commit comments

Comments
 (0)