From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Julian Goacher <julian.goacher@gmail.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: Modifying a bare repo directly
Date: Mon, 10 Apr 2017 10:07:02 -0400 [thread overview]
Message-ID: <20170410140702.bndmudfeofchc2ii@sigill.intra.peff.net> (raw)
In-Reply-To: <CACBZZX7aAHdrvH3wucoQYvZ26mNDYvo3ue4XR0TFF7BxBSWaxw@mail.gmail.com>
On Mon, Apr 10, 2017 at 12:33:18PM +0200, Ævar Arnfjörð Bjarmason wrote:
> On Mon, Apr 10, 2017 at 12:09 PM, Julian Goacher
> <julian.goacher@gmail.com> wrote:
> > Hi -
> >
> > Is it possible to modify a bare repo directly? e.g. is it possible to
> > insert a file into a bare repo without first cloning a non-bare copy?
> > I'm thinking along the lines of a command or sequence of commands that
> > modifies the file index and then copies the file blob into /objects,
> > but in a situation where the new file exists separately from the
> > target repo.
>
> Yes you use the plumbing commands (see "man git", search for plumbing), e.g.:
>
> git init --bare mybare.git
> cd mybare.git
> echo hello | git hash-object --stdin -w >obj
> $ printf "100644 blob $(cat obj)\thello.txt\n" | git mktree
> aaa96ced2d9a1c8e72c56b253a0e2fe78393feb7
> $ git commit-tree -m "1st commit" aaa96ced2d9a1c8e72c56b253a0e2fe78393feb7
> 318448647ab7a2b1f78c87cb8a05ac0cf172fbb8
This is definitely the right track, but if you're going to be modifying
an existing tree (and not just creating a new one), I'd suggest using
using a temporary index:
export GIT_INDEX_FILE=my-index
parent=$(git rev-parse HEAD)
git read-tree $parent
obj=$(echo hello | git hash-object --stdin -w)
git update-index --add --cacheinfo 100644,$obj,hello.txt
[...and other index changes if you want...]
tree=$(git write-tree)
commit=$(git commit-tree -p $parent $tree)
git update-ref HEAD $commit $parent
rm -f $GIT_INDEX_FILE
That's a bit simpler because it handles modifications to existing trees
(rather than overwriting), and it handles changes to nested subtrees (to
edit "deep/subdir/hello.txt" using mktree, you have to issue three
separate mktree commands).
-Peff
next prev parent reply other threads:[~2017-04-10 14:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 10:09 Modifying a bare repo directly Julian Goacher
2017-04-10 10:33 ` Ævar Arnfjörð Bjarmason
2017-04-10 14:07 ` Jeff King [this message]
2017-04-10 18:22 ` Eric Wong
2017-04-11 21:35 ` Julian Goacher
2017-04-12 0:48 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170410140702.bndmudfeofchc2ii@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=julian.goacher@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).