Re: How to put tree into index

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2013-11-20 15:47, Alexander GQ Gerasiov wrote:
[...]
> So my question is
> How to put into index tree-object with known sha1 and given name?

I was just reading about something very similar in the Git book:
http://git-scm.com/book/en/Git-Internals-Git-Objects#Tree-Objects
(read the entire Tree Objects section), and then came up with this,
which I think does what you want except it doesn't erase the previous
contents of dir2/subdir1:

mattcen@wasp:repo$ ls -la
total 8
drwxrwxr-x 2 mattcen mattcen 4096 Nov 20 23:12 .
drwx------ 3 mattcen mattcen 4096 Nov 20 23:12 ..

mattcen@wasp:repo$ git init
Initialized empty Git repository in /tmp/with-temp-dir.ZDw19F/repo/.git/

mattcen@wasp:repo(master)$ touch .gitignore

mattcen@wasp:repo(master)$ git add .gitignore

mattcen@wasp:repo(master)$ git commit -m Initial\ commit
[master (root-commit) 43d7ee6] Initial commit
 0 files changed
 create mode 100644 .gitignore

mattcen@wasp:repo(master)$ mkdir -p dir1 dir2/subdir1

mattcen@wasp:repo(master)$ touch dir1/file{1..3} dir2/subdir1/some\ files

mattcen@wasp:repo(master)$ git add -A

mattcen@wasp:repo(master)$ git commit -m Add\ files
[master 2654d91] Add files
 0 files changed
 create mode 100644 dir1/file1
 create mode 100644 dir1/file2
 create mode 100644 dir1/file3
 create mode 100644 dir2/subdir1/some files

mattcen@wasp:repo(master)$ git branch A

mattcen@wasp:repo(master)$ git checkout -b B
Switched to a new branch 'B'

mattcen@wasp:repo(B)$ git cat-file -p A^{tree} | grep dir1
040000 tree 9599fdeb034597d90d72d2f58396dee096885b79    dir1

mattcen@wasp:repo(B)$ git read-tree --prefix=dir2/subdir1 9599fdeb034597d90d72d2f58396dee096885b79

mattcen@wasp:repo(B)$ git write-tree
e1d5abac94058d1f321a3aa087f18d796efc8a0e

mattcen@wasp:repo(B)$ git checkout .

mattcen@wasp:repo(B)$ find *
dir1
dir1/file3
dir1/file1
dir1/file2
dir2
dir2/subdir1
dir2/subdir1/some files
dir2/subdir1/file3
dir2/subdir1/file1
dir2/subdir1/file2


Hope this helps.

-- 
Regards,

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]