Github 如何允许内联文件编辑? (或者如何在裸 git 存储库中添加或编辑文件)

发布于 2024-11-26 20:46:10 字数 272 浏览 0 评论 0原文

我有一个小型应用程序,它管理多个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无需解释 2024-12-03 20:46:10

您可以使用管道命令。

获取你当前的 HEAD,从那里获取树,然后获取你的斑点。

获得 Blob 后,您可以将内容放入文本框中。完成后,您只需对新的 blob 进行哈希处理,创建新的树、新的提交和 tadaam。是“推”的。

PS:请记住您处于裸存储库中,因此请检查您使用的每个命令是否不需要索引或工作目录。


正如这里所问的,这是一个逐步的示例。

首先,我们获取当前文件内容:

> git cat-file -p HEAD:var/test/text.txt
test

我们对该内容进行了一些修改,现在准备好推送新内容。
为了保存该内容,我们将对它进行哈希处理:

> git hash-object -t blob -w var/test/text.txt
9764d221e6b50063b83c0268544c5d5b745ec9c5

这将保存它,并返回该对象(blob)的 sha-1,下一步包括创建一个新文件夹 test ,它将包含我们的 text.txt 文件。但首先让我们看看当前的 test 文件夹是什么样子的:

> git ls-tree HEAD:var/test
100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4    text.txt

所以我们在这里要做的就是将之前的 SHA-1 (9daeafb...) 替换为新树 (9764d22...) 并基于它生成一棵新树(注意 \t)。

> echo -e "100644 blob 9764d221e6b50063b83c0268544c5d5b745ec9c5\ttext.txt" | git mktree
b7788f9e8e9a24be31188167a6a0bc1de9e41d24

太好了,现在我们有了新文件 text.txt 和父文件夹 test,现在我们需要 var

> git ls-tree HEAD:var
040000 tree 9bfb857f532d280ecd7704beb40a2ea4ba332f5a    test

> echo -e "040000 tree b7788f9e8e9a24be31188167a6a0bc1de9e41d24\ttest" | git mktree
536f33626a47138499fade7df6d02327f75d80be

现在我们需要 var 的父级(这是我们存储库的根):

> git ls-tree HEAD
040000 tree 31a6ee5e7d14a0569721632a05234185a109d6bd    var

> echo -e "040000 tree 536f33626a47138499fade7df6d02327f75d80be\tvar" | git mktree
7db3d6bc14cce98ff89ccc285b9d17965f5ca92b

完成了,我们的树已经准备好了。唯一缺少的是实际的提交:

> git commit-tree -p HEAD -m "commit message" 7db3d6bc14cce98ff89ccc285b9d17965f5ca92b
4aa2de2cf9e3e4f5470bcd1ee1e83ef6e4025eaf

但它还没有准备好,现在我们希望提交成为 HEAD,所以最后一步是:

> git update-ref HEAD 4aa2de2cf9e3e4f5470bcd1ee1e83ef6e4025eaf

现在我们完成了。


资源:

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:

> git cat-file -p HEAD:var/test/text.txt
test

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:

> git hash-object -t blob -w var/test/text.txt
9764d221e6b50063b83c0268544c5d5b745ec9c5

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 our text.txt file. But first let's look at what does the current test folder look like:

> git ls-tree HEAD:var/test
100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4    text.txt

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).

> echo -e "100644 blob 9764d221e6b50063b83c0268544c5d5b745ec9c5\ttext.txt" | git mktree
b7788f9e8e9a24be31188167a6a0bc1de9e41d24

Great, so now we have the new file text.txt and the parent folder test, we now need var.

> git ls-tree HEAD:var
040000 tree 9bfb857f532d280ecd7704beb40a2ea4ba332f5a    test

> echo -e "040000 tree b7788f9e8e9a24be31188167a6a0bc1de9e41d24\ttest" | git mktree
536f33626a47138499fade7df6d02327f75d80be

and now we need the parent of var (which is the root of our repository):

> git ls-tree HEAD
040000 tree 31a6ee5e7d14a0569721632a05234185a109d6bd    var

> echo -e "040000 tree 536f33626a47138499fade7df6d02327f75d80be\tvar" | git mktree
7db3d6bc14cce98ff89ccc285b9d17965f5ca92b

And it's done, our tree is ready. The only thing missing is the actual commit:

> git commit-tree -p HEAD -m "commit message" 7db3d6bc14cce98ff89ccc285b9d17965f5ca92b
4aa2de2cf9e3e4f5470bcd1ee1e83ef6e4025eaf

But it isn't ready yet, now we want the commit to be the HEAD, so the very last step is:

> git update-ref HEAD 4aa2de2cf9e3e4f5470bcd1ee1e83ef6e4025eaf

And now we're done.


Resources:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文