# git read-tree doesn't accept tree-ish

7 messages from 2021-08-23 to 2021-08-23. Participants: Nikita Bobko, Elijah Newren, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/56356

## Nikita Bobko, 2021-08-23 17:31

Subject: git read-tree doesn't accept tree-ish
Message-ID: <CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com>
URL: https://gitlist.dev/e/CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-%2Bg%40mail.gmail.com

```
ˋˋˋ
git init
echo foo > foo
git add --all
git commit -m 'foo'

echo bar > foo
git add --all
git commit -m 'bar'

git read-tree HEAD~:foo
ˋˋˋ
EXP: Read information about file `foo` into index
ACT: `fatal: failed to unpack tree object HEAD~:foo`

I expect it to work because manpage says that `git-read-tree` accepts
`<tree-ish>`

```

## Elijah Newren, 2021-08-23 17:38

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <CABPp-BE7JMdWi5DzHkkkZiM-7u1pW3uhwh1W69yEOxaGuAmUbw@mail.gmail.com>
URL: https://gitlist.dev/e/CABPp-BE7JMdWi5DzHkkkZiM-7u1pW3uhwh1W69yEOxaGuAmUbw%40mail.gmail.com
In-Reply-To: <CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com>

```
On Mon, Aug 23, 2021 at 10:32 AM Nikita Bobko <nikitabobko@gmail.com> wrote:
>
> ˋˋˋ
> git init
> echo foo > foo
> git add --all
> git commit -m 'foo'
>
> echo bar > foo
> git add --all
> git commit -m 'bar'
>
> git read-tree HEAD~:foo
> ˋˋˋ
> EXP: Read information about file `foo` into index
> ACT: `fatal: failed to unpack tree object HEAD~:foo`
>
> I expect it to work because manpage says that `git-read-tree` accepts
> `<tree-ish>`

HEAD~:foo is not a tree in your example, it's a blob.  Try running
this: `git cat-file -t HEAD~:foo`, to see the type.

```

## Jeff King, 2021-08-23 18:53

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <YSPuq/HmF3tnYHCA@coredump.intra.peff.net>
URL: https://gitlist.dev/e/YSPuq%2FHmF3tnYHCA%40coredump.intra.peff.net
In-Reply-To: <CAMJzOtxMjEuAy2B3oJqOZEnipmC4OBWxhQLx_baXDHcQ1C7-+g@mail.gmail.com>

```
On Mon, Aug 23, 2021 at 07:31:29PM +0200, Nikita Bobko wrote:

> ˋˋˋ
> git init
> echo foo > foo
> git add --all
> git commit -m 'foo'
> 
> echo bar > foo
> git add --all
> git commit -m 'bar'
> 
> git read-tree HEAD~:foo
> ˋˋˋ
> EXP: Read information about file `foo` into index
> ACT: `fatal: failed to unpack tree object HEAD~:foo`
> 
> I expect it to work because manpage says that `git-read-tree` accepts
> `<tree-ish>`

In your example, "foo" is a blob, not a tree. And thus HEAD~:foo
is not a tree-ish. Just "HEAD~" would be.

What are you trying to do?

-Peff

```

## Nikita Bobko, 2021-08-23 19:10

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com>
URL: https://gitlist.dev/e/CAMJzOtz_h0iEL1VQCFvvLzw3XnL%2BqM%3Df%2BBvkmsTU%3Dps%2B0VA7RA%40mail.gmail.com
In-Reply-To: <YSPuq/HmF3tnYHCA@coredump.intra.peff.net>

```
Yes, now I see. Thanks!

I was trying to read state of a particular directory/file from a
particular revision into my index but so far didn't manage to do it
reliably.

I was using `git read-tree <hash>:<path>` and it doesn't work for
files (because they are blobs not tree-ish as you elaborated it to me)
and for directories, in my cases, it fails with not so helpful
message:
ˋˋˋ
error: Entry '<path>/<subpath>' overlaps with '<path>/<subpath>'.  Cannot bind.
ˋˋˋ

`git checkout <hash> -- <path>` also doesn't work in my case because
if any file is removed in `<hash>` but not in my HEAD then `git
checkout` doesn't remove the file in my HEAD

On Mon, Aug 23, 2021 at 8:53 PM Jeff King <peff@peff.net> wrote:
>
> On Mon, Aug 23, 2021 at 07:31:29PM +0200, Nikita Bobko wrote:
>
> > ˋˋˋ
> > git init
> > echo foo > foo
> > git add --all
> > git commit -m 'foo'
> >
> > echo bar > foo
> > git add --all
> > git commit -m 'bar'
> >
> > git read-tree HEAD~:foo
> > ˋˋˋ
> > EXP: Read information about file `foo` into index
> > ACT: `fatal: failed to unpack tree object HEAD~:foo`
> >
> > I expect it to work because manpage says that `git-read-tree` accepts
> > `<tree-ish>`
>
> In your example, "foo" is a blob, not a tree. And thus HEAD~:foo
> is not a tree-ish. Just "HEAD~" would be.
>
> What are you trying to do?
>
> -Peff

```

## Elijah Newren, 2021-08-23 19:23

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <CABPp-BHibnrJYAYe-uX_ib7DFR5kkd=G2Jh+nhANPkfbnoFOzw@mail.gmail.com>
URL: https://gitlist.dev/e/CABPp-BHibnrJYAYe-uX_ib7DFR5kkd%3DG2Jh%2BnhANPkfbnoFOzw%40mail.gmail.com
In-Reply-To: <CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com>

```
Hi,

On Mon, Aug 23, 2021 at 12:09 PM Nikita Bobko <nikitabobko@gmail.com> wrote:
>
> Yes, now I see. Thanks!
>
> I was trying to read state of a particular directory/file from a
> particular revision into my index but so far didn't manage to do it
> reliably.

Please don't top-post on this list.

> I was using `git read-tree <hash>:<path>` and it doesn't work for
> files (because they are blobs not tree-ish as you elaborated it to me)
> and for directories, in my cases, it fails with not so helpful
> message:
> ˋˋˋ
> error: Entry '<path>/<subpath>' overlaps with '<path>/<subpath>'.  Cannot bind.
> ˋˋˋ
>
> `git checkout <hash> -- <path>` also doesn't work in my case because
> if any file is removed in `<hash>` but not in my HEAD then `git
> checkout` doesn't remove the file in my HEAD

Have you tried `git restore --source=<hash> -- <path>` ?

```

## Junio C Hamano, 2021-08-23 19:27

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <xmqq5yvwq7w5.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq5yvwq7w5.fsf%40gitster.g
In-Reply-To: <CAMJzOtz_h0iEL1VQCFvvLzw3XnL+qM=f+BvkmsTU=ps+0VA7RA@mail.gmail.com>

```
Nikita Bobko <nikitabobko@gmail.com> writes:

> `git checkout <hash> -- <path>` also doesn't work in my case because
> if any file is removed in `<hash>` but not in my HEAD then `git
> checkout` doesn't remove the file in my HEAD

Look for "--no-overlay" option in "git checkout", perhaps?

```

## Nikita Bobko, 2021-08-23 19:38

Subject: Re: git read-tree doesn't accept tree-ish
Message-ID: <CAMJzOtwwxKz3_cgpOOOx-tYE-qHUyMWfXu+dKEBHhz2Aov4MyQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAMJzOtwwxKz3_cgpOOOx-tYE-qHUyMWfXu%2BdKEBHhz2Aov4MyQ%40mail.gmail.com
In-Reply-To: <xmqq5yvwq7w5.fsf@gitster.g>

```
> Have you tried `git restore --source=<hash> -- <path>` ?

At a glance, it looks what I am looking for

> Look for "--no-overlay" option in "git checkout", perhaps?

Oh, and it works too. So many ways to do almost exactly the same thing...

Anyway, thanks everyone for the help! My issue may be considered as
resolved. Now I will dig into manpages and experiments to see which of
the suggested variants suits me best

On Mon, Aug 23, 2021 at 9:27 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Nikita Bobko <nikitabobko@gmail.com> writes:
>
> > `git checkout <hash> -- <path>` also doesn't work in my case because
> > if any file is removed in `<hash>` but not in my HEAD then `git
> > checkout` doesn't remove the file in my HEAD
>
> Look for "--no-overlay" option in "git checkout", perhaps?

```
