Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过git python添加/提交和推送存储库?_Python_Git_Gitpython - Fatal编程技术网

如何通过git python添加/提交和推送存储库?

如何通过git python添加/提交和推送存储库?,python,git,gitpython,Python,Git,Gitpython,我正在尝试使用git python添加、提交和推送到存储库。根据不完整的文档和示例,我尝试了以下方法: myrepo=Repo('Repos/hello world/.git')) #对README.md进行更改 myrepo.index.add('README.md') myrepo.index.commit(“更新版权年”) myrepo.git.push(“源代码”、“版权更新程序”)### 我签出了存储库hello\u world,并将其放在文件夹Repos下。我确实更改了一个文件,R

我正在尝试使用git python添加、提交和推送到存储库。根据不完整的文档和示例,我尝试了以下方法:

myrepo=Repo('Repos/hello world/.git'))
#对README.md进行更改
myrepo.index.add('README.md')
myrepo.index.commit(“更新版权年”)
myrepo.git.push(“源代码”、“版权更新程序”)###
我签出了存储库
hello\u world
,并将其放在文件夹
Repos
下。我确实更改了一个文件,
README.md
。但是有了这个代码,我得到了一个错误

git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
   cmdline: git push origin copyright_updater
   stderr: 'error: src refspec copyright_updater does not match any.
 error: failed to push some refs to 'git@github.com:alex4200/hello-world.git''
在标记行中


如何修复它,以便将更改推送到新分支并在GitHub上创建pull请求?

您需要做的是直接使用git。这将在本教程的末尾解释

基本上,当您有一个
repo
对象时,您可以像

repo.git.function(param1, param2, param3, ...) 
例如,调用git命令

git push --set-upstream origin testbranch
是吗

repo.git.push("--set-upstream", "origin", "testbranch")
适用有关“-”的特殊规则

因此,为了创建一个新分支并将其推送到github,完整的序列变得

repo = Repo('Repos/hello-world/.git')
# make changes to README.md
repo.index.add('README.md')
repo.index.commit("My commit message")
repo.git.checkout("-b", "new_branch")
repo.git.push("--set-upstream","origin","new_branch")

如何在github上为新分支创建拉请求,是我还没有掌握的另一种魔法…

拉请求不是Git的一部分。GitHub上的Pull请求使用GitHub URL和序列;Bitbucket上的pull请求使用Bitbucket URL和序列(与GitHub上的请求不同);等等