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(), "\n", " ", -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
}