这个 Git 问题与 another one 非常相似关于SVN。
我有一个充满大文件的存储库,我需要向其中添加一个文件。这在 SVN 中曾经非常容易。
svn import -m "Adding just a file"file_name http://path/to/svn/repo/file_name
如何在 Git 中完成这个简单的任务?
最佳答案
对于 GitHub(不是 git
本身),the GitHub API提供了一种无需克隆即可创建文件的方法:
https://developer.github.com/v3/repos/contents/#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 输入:
{
"message": "my commit message",
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
所以你可以编写一个脚本来对文件内容进行 base64 编码,然后让它使用 curl
或类似的方式将上面的一些 JSON 发送到 https://api.github.com/repos/:owner/:repo/contents/:path
如果成功,您将获得 a JSON response back包括所创建文件的 GitHub URL。
无需克隆也可以更新:https://developer.github.com/v3/repos/contents/#update-a-file
关于git - 如何在不首先克隆整个 repo 的情况下将文件添加到远程 Git repo (Github),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19619450/