use git add
git commit
git push
with "github.com/go-git/go-git/v5".
go get github.com/go-xlan/gogit
First, create a new Git client instance by calling the New
function with the repository's root directory:
package main
import (
"fmt"
"log"
"github.com/go-xlan/gogit"
"github.com/yyle88/done"
)
func main() {
client := done.VPE(gogit.New("/path/to/your/repository")).Nice()
fmt.Println("Git client initialized!")
}
To add all changes (including deletions) to the Git index (staging area), use the AddAll
method:
err := client.AddAll()
done.Done(err)
To view the current status of the working tree, use the Status
method:
status, err := client.Status()
done.Done(err)
fmt.Println("Git Status: ", status)
To commit all changes, use the CmtAll
method. You need to provide a CommitMessage
struct, which defines the commit message and signature.
commitMessage := gogit.CommitMessage{
Name: "Your Name",
Emails: "[email protected]",
Message: "Your commit message",
}
commitHash, err := client.CmtAll(commitMessage)
done.Done(err)
fmt.Println("Commit successful! Commit hash: ", commitHash)
To amend the latest commit (e.g., to modify the commit message or add more changes), use the CAmend
method:
commitMessage := gogit.CommitMessage{
Message: "Amended commit message",
}
commitHash, err := client.CAmend(commitMessage)
done.Done(err)
fmt.Println("Amend successful! Commit hash: ", commitHash)
gogit
provides additional functionality such as retrieving commit hashes and logs. Feel free to explore the source code for more advanced features and extensions.
-
New(root string) (*Client, error)
Initializes and returns a newClient
instance for interacting with the Git repository located at the specified path. -
AddAll() error
Adds all changes (including deletions) to the Git index (staging area). -
Status() (git.Status, error)
Returns the current status of the working tree. -
CmtAll(options CommitMessage) (string, error)
Commits all changes with the providedCommitMessage
for the commit's author and message. -
CAmend(options CommitMessage) (string, error)
Amends the latest commit with the provided commit message or adds new changes. The commit is amended using the--amend
flag.
Contributions are welcome! If you'd like to help improve this project, please feel free to:
- Open an issue for bug reports or feature requests
- Submit a pull request with your improvements
MIT License - See the LICENSE
file for more details.
Give me stars. Thank you!!!