• <tfoot id='IGZPo'></tfoot>

    <small id='IGZPo'></small><noframes id='IGZPo'>

      <bdo id='IGZPo'></bdo><ul id='IGZPo'></ul>

      <i id='IGZPo'><tr id='IGZPo'><dt id='IGZPo'><q id='IGZPo'><span id='IGZPo'><b id='IGZPo'><form id='IGZPo'><ins id='IGZPo'></ins><ul id='IGZPo'></ul><sub id='IGZPo'></sub></form><legend id='IGZPo'></legend><bdo id='IGZPo'><pre id='IGZPo'><center id='IGZPo'></center></pre></bdo></b><th id='IGZPo'></th></span></q></dt></tr></i><div id='IGZPo'><tfoot id='IGZPo'></tfoot><dl id='IGZPo'><fieldset id='IGZPo'></fieldset></dl></div>

      1. <legend id='IGZPo'><style id='IGZPo'><dir id='IGZPo'><q id='IGZPo'></q></dir></style></legend>
      2. 如何使用python将本地文件推送到github?(或通过 Python 发布提交)

        时间:2023-07-21

            <tbody id='Fxw7D'></tbody>
          <i id='Fxw7D'><tr id='Fxw7D'><dt id='Fxw7D'><q id='Fxw7D'><span id='Fxw7D'><b id='Fxw7D'><form id='Fxw7D'><ins id='Fxw7D'></ins><ul id='Fxw7D'></ul><sub id='Fxw7D'></sub></form><legend id='Fxw7D'></legend><bdo id='Fxw7D'><pre id='Fxw7D'><center id='Fxw7D'></center></pre></bdo></b><th id='Fxw7D'></th></span></q></dt></tr></i><div id='Fxw7D'><tfoot id='Fxw7D'></tfoot><dl id='Fxw7D'><fieldset id='Fxw7D'></fieldset></dl></div>
            <legend id='Fxw7D'><style id='Fxw7D'><dir id='Fxw7D'><q id='Fxw7D'></q></dir></style></legend>

                <bdo id='Fxw7D'></bdo><ul id='Fxw7D'></ul>

              • <small id='Fxw7D'></small><noframes id='Fxw7D'>

                • <tfoot id='Fxw7D'></tfoot>

                  本文介绍了如何使用python将本地文件推送到github?(或通过 Python 发布提交)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下是我认为应该可行的三种方法,因此按顺序尝试:

                  Here are three methods I thought should be feasible so attempted in order:

                  1. 使用pygithub:(Github的python API)发送将请求推送到我的存储库.失败,因为我在 API 中找不到推送函数.我可以看到编辑文件,但是当我打算经常替换文件时,这无济于事.

                  1. Use pygithub: (Github's python API) to send push requests to my repository. Failed because I can find no push functions in the API. I can see edit files, but that doesn't help when I plan on replacing the file often.

                  在 python 子进程 (HTTPS) 的命令行中使用 git push: 这几乎可以工作,但我不知道如何填写用户和密码字段必填.尝试:

                  Use git push in command line from a python subprocess (HTTPS): This almost works, but I cannot figure out how to fill in the user and password fields required. Attempt:

                  import subprocess
                  from pexpect import popen_spawn
                  
                  
                  user = 'GithubUsername'
                  password = '***********'
                  
                  cmd = "cd C:\UsersDropboxgit-test"
                  returned_value = subprocess.call(cmd, shell=True)  # returns the exit code in unix
                  
                  cmd = "git add ." 
                  subprocess.call(cmd, shell=True)
                  
                  cmd = 'git commit -m "python project update"'
                  subprocess.call(cmd, shell=True)
                  
                  cmd = "git remote set-url origin https://github.com/Tehsurfer/git-test.git"
                  subprocess.call(cmd, shell=True)
                  
                  cmd = "git push "
                  child_process = popen_spawn.PopenSpawn(cmd)
                  child_process.expect('User')
                  child_process.sendline(user)
                  child_process.expect('Password')
                  child_process.sendline(password)
                  print('returned value:', returned_value)
                  
                  print('end of commands')`
                  

                • 在 python 子进程 (SSH) 的命令行中使用 git push: 我遇到的问题是我找不到创建 ssh 的方法Windows 命令提示符中的代理.我已经能够通过 本教程 ,但无法通过 Python 与之交互.

                • Use git push in command line from a python subprocess (SSH): The problem I had here is that I cannot find a way to create a ssh agent in the windows command prompt. I have been able to create one in the MINGW64 terminal easily enough via this tutorial , but have no way of interacting with it via Python.

                  推荐答案

                  如何将新文件推送到 GitHub?

                  一个非常相似的问题,我可以修改谁的代码以通过 python 将多个文件推送到 github:

                  A very similar question who's code I was able to modify to make multiple file pushes to github via python:

                  import base64
                  from github import Github
                  from github import InputGitTreeElement
                  
                  user = "GithubUsername"
                  password = "*********"
                  g = Github(user,password)
                  repo = g.get_user().get_repo('git-test') # repo name
                  file_list = [
                      'C:\UsersjesseDropboxSwell-Forecastgit-testindex.html',
                      'C:\UsersjesseDropboxSwell-Forecastgit-testmargin_table.html'
                  ]
                  file_names = [
                      'index.html',
                      'margin_table.html'
                  ]
                  commit_message = 'python commit'
                  master_ref = repo.get_git_ref('heads/master')
                  master_sha = master_ref.object.sha
                  base_tree = repo.get_git_tree(master_sha)
                  
                  element_list = list()
                  for i, entry in enumerate(file_list):
                      with open(entry) as input_file:
                          data = input_file.read()
                      if entry.endswith('.png'): # images must be encoded
                          data = base64.b64encode(data)
                      element = InputGitTreeElement(file_names[i], '100644', 'blob', data)
                      element_list.append(element)
                  
                  tree = repo.create_git_tree(element_list, base_tree)
                  parent = repo.get_git_commit(master_sha)
                  commit = repo.create_git_commit(commit_message, tree, [parent])
                  master_ref.edit(commit.sha)
                  

                  这篇关于如何使用python将本地文件推送到github?(或通过 Python 发布提交)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                • 上一篇:在 Python 中 gzip 文件 下一篇:如何通过 python 脚本在 linux 中设置用户密码?

                  相关文章

                • <small id='LDlAc'></small><noframes id='LDlAc'>

                  <i id='LDlAc'><tr id='LDlAc'><dt id='LDlAc'><q id='LDlAc'><span id='LDlAc'><b id='LDlAc'><form id='LDlAc'><ins id='LDlAc'></ins><ul id='LDlAc'></ul><sub id='LDlAc'></sub></form><legend id='LDlAc'></legend><bdo id='LDlAc'><pre id='LDlAc'><center id='LDlAc'></center></pre></bdo></b><th id='LDlAc'></th></span></q></dt></tr></i><div id='LDlAc'><tfoot id='LDlAc'></tfoot><dl id='LDlAc'><fieldset id='LDlAc'></fieldset></dl></div>
                  <legend id='LDlAc'><style id='LDlAc'><dir id='LDlAc'><q id='LDlAc'></q></dir></style></legend>
                  • <bdo id='LDlAc'></bdo><ul id='LDlAc'></ul>

                      <tfoot id='LDlAc'></tfoot>