doumei9589 2018-03-27 19:56
浏览 52

如何在git2go中修改特定提交的特定提交消息?

Here is what I have tried: Iterate through git log to find the specific commit I want to modify. Next I modify the commit message. Now I want to amend this message to that specific commit. Code snippet as below:

So my problem is this code does not amend the commit message. Not sure where I am going wrong. Since Amend() takes tree as one of the parameter I am assuming the specific commit message should have been pushed to git.

err = odb.ForEach(func(oid *git.Oid) error {
    obj, err := repo.Lookup(oid)
    if err != nil {
        return err
    }

    if obj.Type() != git.ObjectCommit {
        return nil
    }

    commit, err := obj.AsCommit()
    if err != nil {
        return err
    }
    tree, err := commit.Tree()
    if err != nil {
        return err
    } 
    message := strings.Replace(commit.Message(), "
", " ", -1)
    if strings.Contains(message, key) {
        message := strings.Replace(commit.Message(), key, new_key, -1)
        repo, err := commit.Amend("", signature, signature, message, tree)
        remote, err = repo.Remotes.Create("origin", repo.Path())
        head, err := repo.Head()
        branchName := head.Name()
        if err := remote.Push([]string{branchName}, &git.PushOptions{}); err != nil {
            return err
        }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制