# [PATCH] Fix "git checkout -b foo ':/substring'"

3 messages from 2008-02-02 to 2008-02-02. Participants: Junio C Hamano, Daniel Barkalow.
Thread: https://gitlist.dev/t/11823

## Junio C Hamano, 2008-02-02 03:06

Subject: [PATCH] Fix "git checkout -b foo ':/substring'"
Message-ID: <7v1w7w6oq7.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1w7w6oq7.fsf%40gitster.siamese.dyndns.org

```
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>
---

 * As we advertize that ":/string" syntax is usable for any
   command that wnats to take a commit object name in the
   Release Notes, we might want to put this in 1.5.4 final.  It
   looks simple and safe enough.

diff --git a/git-checkout.sh b/git-checkout.sh
index 5621c69..bd74d70 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -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"
@@ -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

```

## Daniel Barkalow, 2008-02-02 08:32

Subject: Re: [PATCH] Fix "git checkout -b foo ':/substring'"
Message-ID: <alpine.LNX.1.00.0802020331210.13593@iabervon.org>
URL: https://gitlist.dev/e/alpine.LNX.1.00.0802020331210.13593%40iabervon.org
In-Reply-To: <7v1w7w6oq7.fsf@gitster.siamese.dyndns.org>

```
On Fri, 1 Feb 2008, Junio C Hamano wrote:

> 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.

Could we have a test for this? I'm not exactly sure how to use it, and I 
want to make sure my C version works.

	-Daniel
*This .sig left intentionally blank*

```

## Junio C Hamano, 2008-02-02 09:01

Subject: Re: [PATCH] Fix "git checkout -b foo ':/substring'"
Message-ID: <7vprvf3f6g.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vprvf3f6g.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <alpine.LNX.1.00.0802020331210.13593@iabervon.org>

```
Daniel Barkalow <barkalow@iabervon.org> writes:

> Could we have a test for this? I'm not exactly sure how to use it, and I 
> want to make sure my C version works.

$ git checkout -b newone ':/Initial revision of "git"'
$ git log
commit e83c5163316f89bfbde7d9ab23ca2e25604af290
Author: Linus Torvalds <torvalds@ppc970.osdl.org>
Date:   Thu Apr 7 15:13:13 2005 -0700

    Initial revision of "git", the information manager from hell

;-)

```
