# Re: [PATCH] git-checkout: allow pathspec to recover lost working tree directory

4 messages from 2006-11-15 to 2006-11-17. Participants: Junio C Hamano, Petr Baudis, Anand Kumria.
Thread: https://gitlist.dev/t/43322

## Junio C Hamano, 2006-11-15 19:07

Subject: [PATCH] git-checkout: allow pathspec to recover lost working tree directory
Message-ID: <7vbqn8msuw.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbqn8msuw.fsf%40assigned-by-dhcp.cox.net

```
It is often wanted on the #git channel that this were to work to
recover removed directory:

	rm -fr Documentation
	git checkout -- Documentation
	git checkout HEAD -- Documentation ;# alternatively

Now it does.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 * Back to fixing usability issues one at a time instead of
   throwing everything away with bathwater.

 git-checkout.sh |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/git-checkout.sh b/git-checkout.sh
index eb28b29..737abd0 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -112,7 +112,11 @@ Did you intend to checkout '$@' which ca
 		git-ls-tree --full-name -r "$new" "$@" |
 		git-update-index --index-info || exit $?
 	fi
-	git-checkout-index -f -u -- "$@"
+
+	# Make sure the request is about existing paths.
+	git-ls-files --error-unmatch -- "$@" >/dev/null || exit
+	git-ls-files -- "$@" |
+	git-checkout-index -f -u --stdin
 	exit $?
 else
 	# Make sure we did not fall back on $arg^{tree} codepath
-- 
1.4.4


```

## Anand Kumria, 2006-11-16 01:17

Subject: Re: [PATCH] git-checkout: allow pathspec to recover lost working tree directory
Message-ID: <ejge6q$bm7$1@sea.gmane.org>
URL: https://gitlist.dev/e/ejge6q%24bm7%241%40sea.gmane.org
In-Reply-To: <7vbqn8msuw.fsf@assigned-by-dhcp.cox.net>

```
On Wed, 15 Nov 2006 11:07:19 -0800, Junio C Hamano wrote:

> It is often wanted on the #git channel that this were to work to
> recover removed directory:
> 
> 	rm -fr Documentation
> 	git checkout -- Documentation
> 	git checkout HEAD -- Documentation ;# alternatively
> 
> Now it does.

One thing I often seem to do is make some changes, test them out and
remove the file if it wa a dead end and get my original back with
'cg-restore <file>'. Does this mean that the git equivalent will be 'git
checkout -- <file>' as well?

Thanks,
Anand

```

## Junio C Hamano, 2006-11-16 02:00

Subject: Re: [PATCH] git-checkout: allow pathspec to recover lost working tree directory
Message-ID: <7vlkmcgngc.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vlkmcgngc.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <ejge6q$bm7$1@sea.gmane.org>

```
"Anand Kumria" <wildfire@progsoc.org> writes:

> On Wed, 15 Nov 2006 11:07:19 -0800, Junio C Hamano wrote:
>
>> It is often wanted on the #git channel that this were to work to
>> recover removed directory:
>> 
>> 	rm -fr Documentation
>> 	git checkout -- Documentation
>> 	git checkout HEAD -- Documentation ;# alternatively
>> 
>> Now it does.
>
> One thing I often seem to do is make some changes, test them out and
> remove the file if it wa a dead end and get my original back with
> 'cg-restore <file>'. Does this mean that the git equivalent will be 'git
> checkout -- <file>' as well?

Naming individual files has been supported for a long time.
What this patch adds is an ability to name a whole directory to
restore to the index state or a named commit state).

```

## Petr Baudis, 2006-11-17 15:44

Subject: Re: [PATCH] git-checkout: allow pathspec to recover lost working tree directory
Message-ID: <20061117154459.GF7201@pasky.or.cz>
URL: https://gitlist.dev/e/20061117154459.GF7201%40pasky.or.cz
In-Reply-To: <7vbqn8msuw.fsf@assigned-by-dhcp.cox.net>

```
On Wed, Nov 15, 2006 at 08:07:19PM CET, Junio C Hamano wrote:
> diff --git a/git-checkout.sh b/git-checkout.sh
> index eb28b29..737abd0 100755
> --- a/git-checkout.sh
> +++ b/git-checkout.sh
> @@ -112,7 +112,11 @@ Did you intend to checkout '$@' which ca
>  		git-ls-tree --full-name -r "$new" "$@" |
>  		git-update-index --index-info || exit $?
>  	fi
> -	git-checkout-index -f -u -- "$@"
> +
> +	# Make sure the request is about existing paths.
> +	git-ls-files --error-unmatch -- "$@" >/dev/null || exit
> +	git-ls-files -- "$@" |
> +	git-checkout-index -f -u --stdin
>  	exit $?
>  else
>  	# Make sure we did not fall back on $arg^{tree} codepath

Wouldn't it be better to fix git-checkout-index to checkout a whole
directory if specified?

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1

```
