This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 22a6ef9
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Commit Day | ||
|
||
你是不是跟 [@YamiOdymel](https://github.com/YamiOdymel) 一樣,懶的在做完某些事情的當下就直接 Commit 呢?但如果之後達到某個進度才全部一起 Commit 的話就會失去了你在 GitHub 的 Commit 連續紀錄,到底該怎麼辦呢? | ||
|
||
這個時候 Commit Day 就是你的好朋友!Commit Day 會在你 Commit 完所有檔案後,掃描這些檔案的最後變更日期,並以該日期作為 Commit 的日期(而不是你 Commit 當下的時間)!這意味著你終於可以在今天以之前的日期 Commit 那些以往的變更了! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
. "fmt" | ||
"os" | ||
"os/exec" | ||
"regexp" | ||
"time" | ||
) | ||
|
||
func main() { | ||
var c []commitBox | ||
|
||
app := "git" | ||
|
||
arg0 := "log" | ||
arg1 := "--branches" | ||
arg2 := "--not" | ||
arg3 := "--remotes" | ||
|
||
cmd := exec.Command(app, arg0, arg1, arg2, arg3) | ||
stdout, err := cmd.Output() | ||
|
||
if err != nil { | ||
Println(err.Error()) | ||
return | ||
} | ||
|
||
//Print() | ||
|
||
commitRegexp := regexp.MustCompile(`commit (.*)\nAuthor: (.*)\nDate: (.*)\n\n (.*)`) | ||
commits := commitRegexp.FindAllStringSubmatch(string(stdout), -1) | ||
|
||
for _, commit := range commits { | ||
id := commit[1] | ||
//author := commit[2] | ||
date := commit[3] | ||
message := commit[4] | ||
|
||
app := "git" | ||
|
||
arg0 := "show" | ||
arg1 := id | ||
|
||
cmd := exec.Command(app, arg0, arg1) | ||
stdout, err := cmd.Output() | ||
|
||
if err != nil { | ||
Println(err.Error()) | ||
return | ||
} | ||
|
||
diffRegexp := regexp.MustCompile(`diff --git a\/(.*) b\/(.*)`) | ||
diffs := diffRegexp.FindAllStringSubmatch(string(stdout), -1) | ||
|
||
var srcs []string | ||
var lastTime time.Time | ||
for _, diff := range diffs { | ||
src := diff[1] | ||
|
||
file, err := os.Stat(src) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
//Printf("%s, %s, %s, %s\n", id, src, file.ModTime(), message) | ||
|
||
if lastTime.Before(file.ModTime()) { | ||
lastTime = file.ModTime() | ||
} | ||
srcs = append(srcs, src) | ||
} | ||
|
||
c = append(c, commitBox{ | ||
files: srcs, | ||
message: message, | ||
oldDate: date, | ||
newDate: lastTime.Format("Mon Jan 2 15:04:05 2006 -0700"), | ||
}) | ||
} | ||
|
||
app = "git" | ||
|
||
arg0 = "reset" | ||
arg1 = "origin/master" | ||
|
||
cmd = exec.Command(app, arg0, arg1) | ||
stdout, err = cmd.Output() | ||
|
||
if err != nil { | ||
Println(err.Error()) | ||
return | ||
} | ||
|
||
//Println(string(stdout)) | ||
|
||
for _, v := range c { | ||
|
||
app := "git" | ||
argAdd := []string{"add"} | ||
|
||
for _, k := range v.files { | ||
argAdd = append(argAdd, k) | ||
} | ||
|
||
cmd := exec.Command(app, argAdd...) | ||
_, err := cmd.Output() | ||
|
||
if err != nil { | ||
Println(err.Error()) | ||
return | ||
} | ||
//Println(string(stdout)) | ||
|
||
app = "git" | ||
arg0 := "commit" | ||
arg1 := "-m" | ||
arg2 := Sprintf(`%s`, v.message) | ||
arg3 := "--date" | ||
arg4 := Sprintf(`"%s"`, v.newDate) | ||
|
||
cmd = exec.Command(app, arg0, arg1, arg2, arg3, arg4) | ||
stdout, err = cmd.Output() | ||
|
||
if err != nil { | ||
Println(err.Error()) | ||
return | ||
} | ||
//Println(string(stdout)) | ||
|
||
Printf("%s, %s, %s -> %s\n", v.files, v.message, v.oldDate, v.newDate) | ||
} | ||
|
||
} | ||
|
||
type commitBox struct { | ||
files []string | ||
message string | ||
oldDate string | ||
newDate string | ||
} |