Re: Raw commands to add object to existing tree

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

 



On Fri, Aug 21, 2009 at 10:31 PM, D Sundstrom<sunds@xxxxxxxxxx> wrote:
> Both the community git manual:
> http://book.git-scm.com/7_raw_git.html
>
> and Pro Git book:
> http://progit.org/book/ch9-2.html
>
> walk you though low level details of creating objects and trees in git, and
> then committing these new trees.
>
> However, they do not show you how to add and commit into existing trees.

Naturally, you can't change an "existing" tree, because any given tree
(identified by its sha-1 hash) can never change.  You presumably want
to create a *new* tree and commit that.

The easiest way I know to do this is to create a new indexfile, fill
it with what you want, and create the tree for that.

(Warning: untested code follows)

export GIT_INDEX_FILE=/tmp/my-temp-index
git read-tree PREVIOUS_COMMIT_OR_TREE_ID
hash=$(git hash-object NEW_FILE)
git update-index --cacheinfo "0644 $hash path/of/file/in/tree"
commitid=$(echo COMMIT MESSAGE | git commit-tree $(git write-tree))
git update-ref refs/heads/BRANCHNAME $commitid PREVIOUS_COMMIT_OR_TREE_ID

Have fun,

Avery
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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]