Skip to content

Commit

Permalink
Fix "git checkout -b foo ':/substring'"
Browse files Browse the repository at this point in the history
Because ':/substring' extended SHA1 expression cannot take
postfix modifiers such as ^{tree} and ^{commit}, we would need
to do it in multiple steps.  With the patch, you can start a new
branch from a randomly-picked commit whose message has the named
string in it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Feb 2, 2008
1 parent 0509eb2 commit 7dc4642
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions git-checkout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ while test $# != 0; do
done

arg="$1"
if rev=$(git rev-parse --verify "$arg^0" 2>/dev/null)
rev=$(git rev-parse --verify "$arg" 2>/dev/null)
if rev=$(git rev-parse --verify "$rev^0" 2>/dev/null)
then
[ -z "$rev" ] && die "unknown flag $arg"
new_name="$arg"
Expand All @@ -82,11 +83,11 @@ then
fi
new="$rev"
shift
elif rev=$(git rev-parse --verify "$arg^{tree}" 2>/dev/null)
elif rev=$(git rev-parse --verify "$rev^{tree}" 2>/dev/null)
then
# checking out selected paths from a tree-ish.
new="$rev"
new_name="$arg^{tree}"
new_name="$rev^{tree}"
shift
fi
[ "$1" = "--" ] && shift
Expand Down

0 comments on commit 7dc4642

Please sign in to comment.