将东西添加到git裸仓库 [英] Adding things to a git bare repository

查看:109
本文介绍了将东西添加到git裸仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,如果我在裸存储库中有文件,则可以使用git show HEAD:path/to/file访问它们.

I know that if I have files in a bare repository, I can access them using git show HEAD:path/to/file.

但是我可以在不克隆和修改工作树的情况下将新内容添加到裸仓库吗?

But can I add new content to a bare repository without cloning and modifying a working tree?

推荐答案

如果我添加1个文件,则该提交中仅包含1个文件,也就是我们添加了一些新内容,现在它已设置为石头

if I add 1 file, only the 1 file is in that commit, aka we added something new and it's now set in stone

有几种简便的方法可以在裸仓库中将单个文件提交添加到master分支的尖端.

There's several convenient ways to add a single-file commit to the tip of the master branch in a bare repo.

看来我需要创建一个blob对象,将其附加到树上,然后将该树对象附加到提交上.

So it appears i need to create a blob object, attach it to a tree, then attach that tree object to a commit.

所有提交内容的方式都归结为这样做,这只是便捷命令适合您的目的的问题. git add创建一个blob并在索引中为其创建一个条目; git commit进行git write-tree会为索引中的内容添加任何新树,而git commit-tree会添加顶级结果树的提交,并添加git update-ref来保持HEAD最新.裸存储库确实具有HEAD提交,通常会附加到(如master,)分支(也为该文件提供符号引用). . .

All the ways to commit anything boil down to doing that, it's just a question of how well the convenience commands suit your purpose. git add creates a blob and makes an entry for it in the index; git commit does a git write-tree that adds any new trees for what's in the index, and a git commit-tree that adds a commit of the top-level resulting tree, and a git update-ref to keep HEAD up to date. Bare repos do have a HEAD commit, generally attached to (aka a symbolic ref for) a branch like master, . . .

因此git的便捷命令几乎已经在执行您想要的操作.尤其是只有一个文件,这将非常容易.

So git's convenience commands are already doing almost exactly what you want. Especially with just the one file, this is going to be very easy.

例如,您的文件出现在~server/data/logs/中,用于分发的裸仓库位于~server/repo.git,您希望已提交的文件位于仓库中的data/logs,并且您始终希望提交最新的日志文件:

Say for example your files appear in ~server/data/logs/, the bare repo you're using for distribution is at ~server/repo.git, you want the committed files to be at data/logs in the repo, and you always want to commit the latest logfile:

#!/bin/sh
cd ~server

# supply locations git ordinarily does on its own in working i.e. non-bare repos:

export GIT_DIR=$PWD/repo.git                  # bare repos don't have defaults for these
export GIT_WORK_TREE=$PWD                     # so supply some to suit our purpose
export GIT_INDEX_FILE=$GIT_DIR/scratch-index  # ...

# payload:  commit (only) the latest file in data/logs:

git read-tree --empty                       # make the index all pretty, and 
git add data/logs/`ls -1t data/logs|sed q`  # everything's ordinary from here - add and 
git commit -m'new logfile'                  # commit

git read-tree从已提交的树中加载索引条目.这是签出,合并和重置以及其他一些我忘记了atm的基础.在这里,我们只希望一个空索引开始,因此--empty.

git read-tree loads index entries from committed trees. It's what underlies checkout and merge and reset and probably some others I'm forgetting atm. Here, we just want an empty index to start, hence --empty.

在使用每台机器上已有的工具的同时使用推/拉/远程同步数据

use push/pull/remote to synchronize data while using a tool already available on every machine

您说的是随着时间的推移数以百万计"的文件,如果您不希望散布完整的历史记录,那么我收集的rsync您已经怀疑这可能是更好的选择.但是-一次一个,每分钟一个新文件,要累积一百万个文件需要花费两年的时间.那么?

You said "millions" of files over time, and if you don't want that full history distributed, rsync as I gather you already suspect might be a better bet. But -- one at a time, one new file per minute, it'll take two years to accumulate just one million. So, ?

无论如何,上述过程可以有效地扩展到每次提交任何少量文件.对于批量工作,有更好的方法.

Whatever, the above procedure is pretty efficiently extensible to any small-ish numbers of files per commit. For bulk work there are better ways.

这篇关于将东西添加到git裸仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆