gitpython - 用消息推送存储

问题描述 投票:1回答:1

我是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文本并粘贴到终端,它按预期工作

python git gitpython
1个回答
1
投票

试试repo.git.stash('push', '-m', 'descriptive message here')

© www.soinside.com 2019 - 2024. All rights reserved.