- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我试图从 Go 中调用 git shortlog
来获取输出,但我遇到了困难。
这是一个工作示例,说明我如何使用 git log
执行此操作:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
runBasicExample()
}
func runBasicExample() {
cmdOut, err := exec.Command("git", "log").Output()
if err != nil {
fmt.Fprintln(os.Stderr, "There was an error running the git command: ", err)
os.Exit(1)
}
output := string(cmdOut)
fmt.Printf("Output: \n%s\n", output)
}
给出预期的输出:
$> go run show-commits.go
Output:
commit 4abb96396c69fa4e604c9739abe338e03705f9d4
Author: TheAndruu
Date: Tue Aug 21 21:55:07 2018 -0400
Updating readme
git shortlog
来做到这一点。出于某种原因...我无法让它与 shortlog 一起使用。又是这个程序,唯一的变化是 git 命令行:
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
runBasicExample()
}
func runBasicExample() {
cmdOut, err := exec.Command("git", "shortlog").Output()
if err != nil {
fmt.Fprintln(os.Stderr, "There was an error running the git command: ", err)
os.Exit(1)
}
output := string(cmdOut)
fmt.Printf("Output: \n%s\n", output)
}
空输出:
$> go run show-commits.go
Output:
我可以直接从命令行运行 git shortlog
,它似乎工作正常。检查 docs , 我被引导相信 'shortlog' 命令是 git 本身的一部分。
任何人都可以帮助指出我可以做些什么吗?
谢谢
最佳答案
事实证明,我能够通过重新阅读 git docs 找到答案
答案就在这一行:
If no revisions are passed on the command line and either standard input is not a terminal or there is no current branch, git shortlog will output a summary of the log read from standard input, without reference to the current repository.
尽管我可以从终端运行 git shortlog
并看到预期的输出,但当通过 exec()
命令运行时,我需要指定分支。
因此在上面的示例中,我将“master”添加到命令参数中,如下所示:
cmdOut, err := exec.Command("git", "shortlog", "master").Output()
一切都按预期进行。
关于git - 从 Go `git shortlog` 调用 'exec()' 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51966053/
我有一个目录,里面有很多 Git repo 子目录,我想积累类似于 git shortlog -sne --no-merges 对于其中的所有 repo 协议(protocol),按用户的所有总提交对
在使用 Jenkins 时遇到一些连线问题, #!/bin/sh set -x #initialize environment export PATH="$HOME/.gem/ruby/2.0.0/b
当我尝试获取以下命令的输出时遇到问题:git shortlog -s -- [文件路径]使用 python 3.6 子进程模块。 这里是代码: import subprocess x = subpro
我正在尝试使用 Git 预提交 Hook 来运行一些样式检查并自动生成一个 AUTHORS 文件,该文件使用 git shortlog 提取所有贡献者的姓名。 我的预提交脚本包括以下内容: #!/bi
我正在尝试将 git 中的日志信息获取到 python 中。我查看了 pygit2 和 gitpython,但似乎都没有提供类似于 git Shortlog 的高级接口(interface)。是否有一
我试图通过这种方式在带有 nodejs 的存储库上获取 git shortlog 的结果: var exec = require('child_process').exec; exec("cd /tm
我试图从 Go 中调用 git shortlog 来获取输出,但我遇到了困难。 这是一个工作示例,说明我如何使用 git log 执行此操作: package main import ( "f
我的场景 在我的 Node 应用程序中,我使用 child_process.spawn从当前存储库查询信息 我构建了一个小函数来返回一个 promise ,该 promise 通过命令的响应来解析:
我想不通。为什么这些行为不同: (shell-command "git log") (shell-command "git shortlog") 第一个按预期工作:返回 0 并将内容打印到 shell
我是一名优秀的程序员,十分优秀!