Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zihuan-yan/go-git-diff
go语言的git diff解析
https://github.com/zihuan-yan/go-git-diff
diff git git-diff git-difftool gitdiff go golang
Last synced: 11 days ago
JSON representation
go语言的git diff解析
- Host: GitHub
- URL: https://github.com/zihuan-yan/go-git-diff
- Owner: zihuan-yan
- License: mit
- Created: 2021-08-28T07:45:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-06-21T05:23:26.000Z (over 2 years ago)
- Last Synced: 2024-06-22T03:21:52.013Z (7 months ago)
- Topics: diff, git, git-diff, git-difftool, gitdiff, go, golang
- Language: Go
- Homepage:
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# go-git-diff [![CI](https://github.com/lower-coder/go-git-diff/actions/workflows/go.yml/badge.svg?branch=main)](https://github.com/lower-coder/go-git-diff/actions/workflows/go.yml) [![CI](https://github.com/lower-coder/go-git-diff/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/lower-coder/go-git-diff/actions/workflows/codeql-analysis.yml)
A tool for developer to parse output of git diff command.
## Usage
- diff: A parser that parse output of git diff command to struct diff.
## Example
```go
package mainimport (
"github.com/lower-coder/go-git-diff/diff"
)const diffText = `diff --git a/file1 b/file1
index 504d2a1..50ccec3 100644
--- a/file1
+++ b/file1
@@ -1,4 +1,4 @@
+add a line
some
lines
-in
file1`func main() {
d := diff.NewDiff()
d.Parse(diffText)
}/*
{
"files": [
{
"mode": 2,
"input": {
"source": "a/file1",
"target": "b/file1"
},
"metas": [
{
"meta_type": "index",
"content": "504d2a1..50ccec3 100644"
}
],
"legends": [
{
"mark": "---",
"content": "a/file1"
},
{
"mark": "+++",
"content": "b/file1"
}
],
"chunks": [
{
"source_range": {
"start": 1,
"length": 4,
"lines": [
{
"mode": 1,
"number": 1,
"content": "some"
},
{
"mode": 1,
"number": 2,
"content": "lines"
},
{
"mode": 3,
"number": 3,
"content": "in"
},
{
"mode": 1,
"number": 4,
"content": "file1"
}
]
},
"target_range": {
"start": 1,
"length": 4,
"lines": [
{
"mode": 2,
"number": 1,
"content": "add a line"
},
{
"mode": 1,
"number": 2,
"content": "some"
},
{
"mode": 1,
"number": 3,
"content": "lines"
},
{
"mode": 1,
"number": 4,
"content": "file1"
}
]
}
}
]
}
]
}
*/
```[![Go Report Card](https://goreportcard.com/badge/github.com/lower-coder/go-git-diff)](https://goreportcard.com/report/github.com/lower-coder/go-git-diff)
[![license](https://img.shields.io/github/license/lower-coder/go-git-diff)](https://img.shields.io/github/license/lower-coder/go-git-diff)
[![go-version](https://img.shields.io/github/go-mod/go-version/lower-coder/go-git-diff)](https://img.shields.io/github/go-mod/go-version/lower-coder/go-git-diff)
[![contributors](https://img.shields.io/github/contributors/lower-coder/go-git-diff)](https://img.shields.io/github/contributors/lower-coder/go-git-diff)
[![stars](https://img.shields.io/github/stars/lower-coder/go-git-diff)](https://img.shields.io/github/stars/lower-coder/go-git-diff)
[![lines](https://img.shields.io/tokei/lines/github/lower-coder/go-git-diff)](https://img.shields.io/tokei/lines/github/lower-coder/go-git-diff)
[![downloads](https://img.shields.io/github/downloads/lower-coder/go-git-diff/total)](https://img.shields.io/github/downloads/lower-coder/go-git-diff/total)