Web lists-archives.com

Re: Modifying a bare repo directly




On Mon, Apr 10, 2017 at 12:09 PM, Julian Goacher
<julian.goacher@xxxxxxxxx> 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
$ git show 318448647ab7a2b1f78c87cb8a05ac0cf172fbb8
commit 3184486
Author: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx>
Date:   Mon Apr 10 12:29:22 2017 +0200

    1st commit

diff --git a/hello.txt b/hello.txt
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/hello.txt
@@ -0,0 +1 @@
+hello
$ git update-ref refs/heads/master 318448647ab7a2b1f78c87cb8a05ac0cf172fbb8

Now when you clone this repo you'll have that one commit.