Github 如何允许内联文件编辑? (或者如何在裸 git 存储库中添加或编辑文件)
我有一个小型应用程序,它管理多个 git 存储库,类似于 Github/Gitorious。 Github 允许内联文件编辑,我想知道是否有人知道如何进行管理这个。
我最初的想法是,它将对存储库进行完整克隆,使用您的提交来替换文件、提交和推送,但这对于像 Linux 内核这样的大型存储库来说似乎是一个非常昂贵的操作。
关于向裸存储库添加和编辑文件的更有效方法有什么想法吗?
I have a small application that manages several git repositories similar to Github/Gitorious. Github allows for inline file editing, and I'd like to know if anyone has any idea on how they manage this.
My initial thought was that it would do a complete clone of the repository, use your submission to replace the file, commit, and push, but this seems like an very expensive operation with large repositories like the linux kernel.
Any ideas on a more efficient way to add and edit files to a bare repository?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用管道命令。
获取你当前的 HEAD,从那里获取树,然后获取你的斑点。
获得 Blob 后,您可以将内容放入文本框中。完成后,您只需对新的 blob 进行哈希处理,创建新的树、新的提交和 tadaam。是“推”的。
PS:请记住您处于裸存储库中,因此请检查您使用的每个命令是否不需要索引或工作目录。
正如这里所问的,这是一个逐步的示例。
首先,我们获取当前文件内容:
我们对该内容进行了一些修改,现在准备好推送新内容。
为了保存该内容,我们将对它进行哈希处理:
这将保存它,并返回该对象(blob)的 sha-1,下一步包括创建一个新文件夹
test
,它将包含我们的text.txt
文件。但首先让我们看看当前的test
文件夹是什么样子的:所以我们在这里要做的就是将之前的 SHA-1 (
9daeafb...
) 替换为新树 (9764d22...
) 并基于它生成一棵新树(注意\t
)。太好了,现在我们有了新文件
text.txt
和父文件夹test
,现在我们需要var
。现在我们需要 var 的父级(这是我们存储库的根):
完成了,我们的树已经准备好了。唯一缺少的是实际的提交:
但它还没有准备好,现在我们希望提交成为 HEAD,所以最后一步是:
现在我们完成了。
资源:
You can use plumbing commands.
Get your current HEAD, get the tree from there then your blobs.
Once you have the blob you can put the content in a textbox. When it's finished you just have to hash the new blob, create the new tree, the new commit and tadaam. It's "pushed".
PS: Remember you're in a bare repository, so check that every command you use don't need the index nor the working directory.
As it has been asked here is a step by step example.
First we get the current file content:
We do our little modification on that content and now have a new content ready to be pushed.
To save that content we're going to hash it:
This will save it, and return a sha-1 of that object (blob), the very next step consist in creating a new folder
test
which will contain ourtext.txt
file. But first let's look at what does the currenttest
folder look like:So what we want to do here, is replace the previous SHA-1 (
9daeafb...
) with the new one (9764d22...
) and generate a new tree based on that (pay attention to the\t
).Great, so now we have the new file
text.txt
and the parent foldertest
, we now needvar
.and now we need the parent of
var
(which is the root of our repository):And it's done, our tree is ready. The only thing missing is the actual commit:
But it isn't ready yet, now we want the commit to be the HEAD, so the very last step is:
And now we're done.
Resources: