git read-tree doesn't accept tree-ish

5 messages, 3 authors, 2021-08-23 · open the first message on its own page

git read-tree doesn't accept tree-ish

From: Nikita Bobko <hidden>
Date: 2021-08-23 17:30:45

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

Re: git read-tree doesn't accept tree-ish

From: Elijah Newren <hidden>
Date: 2021-08-23 17:38:24

On Mon, Aug 23, 2021 at 10:32 AM Nikita Bobko [off-list ref] 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.

Re: git read-tree doesn't accept tree-ish

From: Jeff King <hidden>
Date: 2021-08-23 18:53:34

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

Re: git read-tree doesn't accept tree-ish

From: Nikita Bobko <hidden>
Date: 2021-08-23 19:09:49

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 [off-list ref] wrote:
On Mon, Aug 23, 2021 at 07:31:29PM +0200, Nikita Bobko wrote:
quoted
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

Re: git read-tree doesn't accept tree-ish

From: Elijah Newren <hidden>
Date: 2021-08-23 19:23:37

Hi,

On Mon, Aug 23, 2021 at 12:09 PM Nikita Bobko [off-list ref] 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>` ?
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help