git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Raw commands to add object to existing tree
@ 2009-08-21 22:31 D Sundstrom
  2009-08-21 22:39 ` Avery Pennarun
  0 siblings, 1 reply; 4+ messages in thread
From: D Sundstrom @ 2009-08-21 22:31 UTC (permalink / raw)
  To: git

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.

Speaking in terms of files, I have a web application that needs to replace
a file in a known directory in a known branch of a bare repository.  I know the
SHA1s of the directory tree and file.  I want to commit directly into a bare
repository to avoid having to manage working directories for different
branches from the web application.

Thanks!
David

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

* Re: Raw commands to add object to existing tree
  2009-08-21 22:31 Raw commands to add object to existing tree D Sundstrom
@ 2009-08-21 22:39 ` Avery Pennarun
  2009-08-21 22:49   ` Linus Torvalds
  0 siblings, 1 reply; 4+ messages in thread
From: Avery Pennarun @ 2009-08-21 22:39 UTC (permalink / raw)
  To: D Sundstrom; +Cc: git

On Fri, Aug 21, 2009 at 10:31 PM, D Sundstrom<sunds@peapod.net> 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

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

* Re: Raw commands to add object to existing tree
  2009-08-21 22:39 ` Avery Pennarun
@ 2009-08-21 22:49   ` Linus Torvalds
  2009-08-21 22:56     ` Avery Pennarun
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Torvalds @ 2009-08-21 22:49 UTC (permalink / raw)
  To: Avery Pennarun; +Cc: D Sundstrom, git



On Fri, 21 Aug 2009, Avery Pennarun wrote:

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

Looks roughly correct, but you need to add a a "-p $PREVIOUS_COMMIT" to 
that git commit-tree thing. Otherwise the new commit will be a root 
commit. Which _might_ be what you want, of course, but I kind of expect it 
wasn't.

And no, I didn't test that either, so there may be other things that need 
fixing too.

Looking at that thing, I have ugly flashbacks to my git scripts in 2005 ;)

			Linus

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

* Re: Raw commands to add object to existing tree
  2009-08-21 22:49   ` Linus Torvalds
@ 2009-08-21 22:56     ` Avery Pennarun
  0 siblings, 0 replies; 4+ messages in thread
From: Avery Pennarun @ 2009-08-21 22:56 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: D Sundstrom, git

On Fri, Aug 21, 2009 at 10:49 PM, Linus
Torvalds<torvalds@linux-foundation.org> wrote:
> Looking at that thing, I have ugly flashbacks to my git scripts in 2005 ;)

It rather resembles my git scripts in 2009, in which I'm using a web
service to let people upload Microsoft Access databases and version
control and branch them.  Long story, but I'm sure glad this plumbing
stuff exists :)

And yes, my scripts use the -p option.  Oops.

Have fun,

Avery

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

end of thread, other threads:[~2009-08-21 22:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-21 22:31 Raw commands to add object to existing tree D Sundstrom
2009-08-21 22:39 ` Avery Pennarun
2009-08-21 22:49   ` Linus Torvalds
2009-08-21 22:56     ` Avery Pennarun

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 NNTP newsgroup(s).