git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git read-tree doesn't accept tree-ish
@ 2021-08-23 17:31 Nikita Bobko
  2021-08-23 17:38 ` Elijah Newren
  2021-08-23 18:53 ` Jeff King
  0 siblings, 2 replies; 7+ messages in thread
From: Nikita Bobko @ 2021-08-23 17:31 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 17:31 git read-tree doesn't accept tree-ish Nikita Bobko
@ 2021-08-23 17:38 ` Elijah Newren
  2021-08-23 18:53 ` Jeff King
  1 sibling, 0 replies; 7+ messages in thread
From: Elijah Newren @ 2021-08-23 17:38 UTC (permalink / raw)
  To: Nikita Bobko; +Cc: Git Mailing List

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 17:31 git read-tree doesn't accept tree-ish Nikita Bobko
  2021-08-23 17:38 ` Elijah Newren
@ 2021-08-23 18:53 ` Jeff King
  2021-08-23 19:10   ` Nikita Bobko
  1 sibling, 1 reply; 7+ messages in thread
From: Jeff King @ 2021-08-23 18:53 UTC (permalink / raw)
  To: Nikita Bobko; +Cc: git

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 18:53 ` Jeff King
@ 2021-08-23 19:10   ` Nikita Bobko
  2021-08-23 19:23     ` Elijah Newren
  2021-08-23 19:27     ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Nikita Bobko @ 2021-08-23 19:10 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Elijah Newren

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 19:10   ` Nikita Bobko
@ 2021-08-23 19:23     ` Elijah Newren
  2021-08-23 19:27     ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Elijah Newren @ 2021-08-23 19:23 UTC (permalink / raw)
  To: Nikita Bobko; +Cc: Jeff King, Git Mailing List

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 19:10   ` Nikita Bobko
  2021-08-23 19:23     ` Elijah Newren
@ 2021-08-23 19:27     ` Junio C Hamano
  2021-08-23 19:38       ` Nikita Bobko
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2021-08-23 19:27 UTC (permalink / raw)
  To: Nikita Bobko; +Cc: Jeff King, git, Elijah Newren

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: git read-tree doesn't accept tree-ish
  2021-08-23 19:27     ` Junio C Hamano
@ 2021-08-23 19:38       ` Nikita Bobko
  0 siblings, 0 replies; 7+ messages in thread
From: Nikita Bobko @ 2021-08-23 19:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, git, Elijah Newren

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-08-23 19:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 17:31 git read-tree doesn't accept tree-ish Nikita Bobko
2021-08-23 17:38 ` Elijah Newren
2021-08-23 18:53 ` Jeff King
2021-08-23 19:10   ` Nikita Bobko
2021-08-23 19:23     ` Elijah Newren
2021-08-23 19:27     ` Junio C Hamano
2021-08-23 19:38       ` Nikita Bobko

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).