Skip to content

Instantly share code, notes, and snippets.

@ssoto
Created February 4, 2025 14:55
Show Gist options
  • Save ssoto/2111e233194a9b1eff9019f913ce8326 to your computer and use it in GitHub Desktop.
Save ssoto/2111e233194a9b1eff9019f913ce8326 to your computer and use it in GitHub Desktop.
Diff between commits
package main
import (
"bytes"
"fmt"
"os/exec"
"strings"
)
// getCommitMessages obtiene los mensajes de commit entre dos commits
func getCommitMessages(oldCommit, newCommit string) ([]string, error) {
// Comando Git para obtener los mensajes de commit
cmd := exec.Command("git", "log", "--pretty=format:%h - %s", oldCommit+".."+newCommit)
// Capturar salida del comando
var out bytes.Buffer
cmd.Stdout = &out
// Ejecutar el comando
err := cmd.Run()
if err != nil {
return nil, err
}
// Dividir la salida en líneas (un commit por línea)
commitMessages := strings.Split(out.String(), "\n")
return commitMessages, nil
}
func main() {
// Hash de los commits (reemplázalos por los que necesites)
oldCommit := "abc1234"
newCommit := "def5678"
// Obtener mensajes de commit
messages, err := getCommitMessages(oldCommit, newCommit)
if err != nil {
fmt.Println("Error obteniendo commits:", err)
return
}
// Imprimir los mensajes de commit
fmt.Println("Mensajes de commit entre", oldCommit, "y", newCommit)
for _, msg := range messages {
fmt.Println(msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment