首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gitpython -使用消息推送stash

gitpython -使用消息推送stash
EN

Stack Overflow用户
提问于 2019-04-15 23:32:21
回答 1查看 447关注 0票数 1

我是gitpython的新手,我想用它来创建一个带有特定消息的stash。我知道它的命令行语法是git stash push -m "descriptive message here",但我不能在gitpython中使用相同的命令。根据unwrapped commands上的文档,看起来下面的代码应该是可能的

代码语言:javascript
复制
import git

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

但是,它会失败,并显示以下错误

代码语言:javascript
复制
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文本并粘贴到终端中,它将按预期工作

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-25 18:27:30

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55692615

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档