gpt4 book ai didi

python - gitpython - 推送带有消息的存储

转载 作者:行者123 更新时间:2023-12-01 08:02:02 25 4
gpt4 key购买 nike

我是 gitpython 的新手,想用它来创建一个包含特定消息的存储。我知道其命令行语法是 git stash push -m "descriptive message here",但我无法从 gitpython 获得相同的命令。根据 unwrapped commands 上的文档,看来下面的代码应该是可以的

import git

repo = git.Repo('/path/to/my/repo')
repo.git.stash('push -m "descriptive message here")

但是失败并出现以下错误

Traceback (most recent call last):
File "/home/addison/miniconda3/envs/openalpr/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-28-827e00236a8a>", line 1, in <module>
repo.git.stash('push -m "descriptive message here"')
File "/home/addison/miniconda3/envs/openalpr/lib/python3.6/site-packages/git/cmd.py", line 548, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/home/addison/miniconda3/envs/openalpr/lib/python3.6/site-packages/git/cmd.py", line 1014, in _call_process
return self.execute(call, **exec_kwargs)
File "/home/addison/miniconda3/envs/openalpr/lib/python3.6/site-packages/git/cmd.py", line 825, in execute
raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
cmdline: git stash push -m "descriptive message here"
stderr: 'usage: git stash list [<options>]
or: git stash show [<stash>]
or: git stash drop [-q|--quiet] [<stash>]
or: git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
or: git stash branch <branchname> [<stash>]
or: git stash save [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [<message>]
or: git stash [push [--patch] [-k|--[no-]keep-index] [-q|--quiet]
[-u|--include-untracked] [-a|--all] [-m <message>]
[-- <pathspec>...]]
or: git stash clear'

如果我从错误消息中复制 cmdline 文本并将其粘贴到终端中,它会按预期工作

最佳答案

尝试repo.git.stash('push', '-m', '此处描述性消息')

关于python - gitpython - 推送带有消息的存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55692615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com