问题描述
这个 Git 问题与另一个很相似 关于 SVN.
This Git question is very similar to another one about SVN.
我有一个装满大文件的存储库,我需要向其中添加一个文件.这曾经在 SVN 中很容易.
I have a repo full of big files and I need to add a single file to it. This used to be very easy in SVN.
svn import -m "只添加一个文件" file_name http://path/to/svn/repo/file_name
如何在 Git 中实现这个简单的任务?
How to achieve this simple task in Git?
推荐答案
对于 GitHub(不是 git
本身),GitHub API 提供了一种无需克隆即可创建文件的方法:
For GitHub (not git
itself), the GitHub API provides a way to create a file without cloning:
https://developer.github.com/v3/存储库/内容/#create-a-file
PUT /repos/:owner/:repo/contents/:path
# Parameters #
----------------------------------------------------------------
Name Type Description
------ ------ -----------------------------------------------
path string Required. The content path.
message string Required. The commit message.
content string Required. The new file content, Base64-encoded.
branch string Branch name. Default: repo's default branch.
JSON 输入的最小示例:
Minimal example JSON input:
{
"message": "my commit message",
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
所以你可以编写一个脚本来对文件内容进行 base64 编码,然后让它使用 curl
或类似的方式将一些 JSON 发送到 https://api.github.com/repos/:owner/:repo/contents/:path
So you can write a script to base64-encode the file contents, then have it use curl
or such to send some JSON as above to https://api.github.com/repos/:owner/:repo/contents/:path
如果成功,您将获得返回一个 JSON 响应包括所创建文件的 GitHub URL.
If it succeeds, you get a JSON response back including the GitHub URL(s) for the created file.
也可以不克隆更新:https://developer.github.com/v3/repos/contents/#update-a-file
这篇关于如何在不首先克隆整个存储库的情况下将文件添加到远程 Git 存储库(Github)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!