这个程序失败了
import git
repo = git.repo.Repo('..')
res = repo.git.rev_list('--since="2024-01-01" master').split('\n')
出现以下错误
git.exc.GitCommandError: Cmd('git') failed due to: exit code(129)
cmdline: git rev-list --since="2024-01-01" master
stderr: 'usage: git rev-list [<options>] <commit>... [--] [<path>...]
尽管命令
git rev-list --since="2024-01-01" master
在命令行中运行得很好。
有什么解决办法吗?
我相信你误用了
repo.git.rev_list
方法。第一个参数是分支名称(或其他提交引用)。您正在有效地运行命令:
['git', 'rev-list', '--since="2024-01-01" master']
也就是说,您正在寻找字面名称为
--since="2024-01-01" master
的分支或其他引用。如果你像这样拼写命令,你应该得到你期望的结果:
res = repo.git.rev_list("master", since="2024-01-01").split('\n')
尽管在我的系统上我必须明确并使用
refs/heads/master
来避免来自 git 的 warning: refname 'master' is ambiguous.
消息。