Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout a Git tree object into working dir?

Tags:

git

I have constructed a tree that contains a couple of files and only exists in the object database. I then added it to the index associated with a path, and committed:

git hash-object -w --stdin
...
abcd1
git hash-object -w --stdin
...
abcd2

git mktree
100755 blob abcd1 a.txt 
100755 blob abcd2 b.txt

# resultant tree sha1:
abc123

git update-index --index-info
100755 tree abc123 fake.tree.path

git commit -m "fake.tree.path tree commit"

This seems to work, but what I want is to be able to then:

git checkout fake.tree.path

And have "a.txt" and "b.txt" written into the working dir. Is this possible?

like image 568
user318904 Avatar asked Feb 20 '26 23:02

user318904


2 Answers

I think what I was doing wrong was this:

git update-index --index-info
100755 tree abc123 fake.tree.path

should have been this:

git update-index --index-info
040000 tree abc123 fake.tree.path

Now doing a git checkout fake.tree.path constructs the directory as desired.

like image 171
user318904 Avatar answered Feb 22 '26 21:02

user318904


  1. empty index git read-tree --empty

  2. read tree object into index git read-tree <tree-isha>

  3. empty working directory except directory .git ls -a | grep -vw .git | xargs rm -fr | xargs rm -fr

  4. checkout index into working tree git checkout-index -a

references

  • Git Pro 2nd ed. Chapter 10 Git Internals. enter link description here
like image 23
dfasfsf Avatar answered Feb 22 '26 22:02

dfasfsf