[英]Commit git to remote repository without cloning any local repository
My question is quite simple, however I don't find any answer on StackOverflow or elsewhere (except this question but without being answered): 我的问题很简单,但是我在StackOverflow或其他地方找不到任何答案(除了这个问题,但没有得到回答):
Does anyone know a way to commit a GIT change "directly" to a remote repository (Github in my case) without cloning the repository in local and having to commit first to local repository then pushing to remote? 有谁知道一种将GIT更改“直接”提交到远程存储库(在我的例子中是Github)而无需在本地克隆存储库而必须先提交到本地存储库然后再推送到远程的方法吗?
Commits will be performed programmatically from Python (by using simply GIT command lines). 提交将通过Python(仅使用GIT命令行)以编程方式执行。 Honestly I don't see the advantage (in my case) of having a separate server (for local repos) and keep huge git repository on it just to push them finally to Github.
老实说,我看不到有一个单独的服务器(用于本地存储库)并在其上保留巨大的git存储库,只是最终将它们推到Github的优势。
You can clone the repo with -n
to not checkout any files. 您可以使用
-n
克隆存储库,以不检出任何文件。
--depth 1
will truncate the history of each file to their last commit --depth 1
将截断每个文件的历史记录到最后一次提交
git clone -n git://path/to/repo.git --depth 1
cd repo
Checkout only the files you need to change for your commit 仅签出您需要更改以提交的文件
git checkout HEAD file.ext
Just be careful to only commit the file you're working on. 请注意只提交您正在处理的文件。 If you do something like
git add .
如果您执行
git add .
you will be committing the deletion of all files you have not checked out! 您将删除所有尚未签出的文件!
You cannot create commits by using Git command line tools (Python or not doesn't matter) — those tools require a local repository and most of them require a local checkout (work tree). 您不能使用Git命令行工具(是否使用Python无关紧要)来创建提交-这些工具需要本地存储库,并且其中大多数需要本地签出(工作树)。
You can create commits using Github API but this is much harder and you need completely different set of tools like pygithub or any other Python Github API wrapper. 您可以使用Github API创建提交,但这要困难得多,并且您需要完全不同的工具集,例如pygithub或任何其他Python Github API包装器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.