相关疑难解决方法(0)

如何使用GitPython获取暂存文件?

我正在使用GitPython计算git中的暂存文件.

对于修改过的文件,我可以使用

repo = git.Repo()
modified_files = len(repo.index.diff(None))
Run Code Online (Sandbox Code Playgroud)

但对于分阶段文件,我找不到解决方案.

我知道,git status --porcelain但我正在寻找更好的其他解决方案.(我希望使用gitpython不是git命令,脚本会更快)

python git gitpython

10
推荐指数
1
解决办法
3198
查看次数

如何使用python将本地文件推送到github?(或通过 Python 发布提交)

有哪些选项可以从 python 提交和推送文件到 github?

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

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

  2. git push在 python 子进程 (HTTPS) 的命令行中使用:这几乎有效,但我不知道如何填写所需的用户和密码字段。试图:

    import subprocess
    from pexpect import popen_spawn
    
    
    user = 'GithubUsername'
    password = '***********'
    
    cmd = "cd C:\\Users\Dropbox\git-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 …
    Run Code Online (Sandbox Code Playgroud)

python git subprocess popen

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

git ×2

python ×2

gitpython ×1

popen ×1

subprocess ×1