63
Keep your GIT history clean Tomasz Brodziński @TomaszBro

Keep you GIT history clean

Embed Size (px)

Citation preview

Page 1: Keep you GIT history clean

Keep your GIT history clean

Tomasz Brodziński

@TomaszBro

Page 2: Keep you GIT history clean
Page 3: Keep you GIT history clean

meaningless messages

“fixing bug”, “minor changes”, “clean up”, “oops”

Page 4: Keep you GIT history clean

repeated messages

“fix bug 9876”

“fix bug 9876”

“fix bug 9876”

Page 5: Keep you GIT history clean

tickets numbers only

“BUG-1234”

Page 6: Keep you GIT history clean

duplicating the code

“add property `foo`”

Page 7: Keep you GIT history clean

too long messages

“It is the big and important commit, which introduces

new functionality to our great application.”

Page 8: Keep you GIT history clean

too big commits

Page 9: Keep you GIT history clean

Commit message – formating and limitations

Page 10: Keep you GIT history clean

First line as summary of changes

● max 50 characters

Page 11: Keep you GIT history clean

First line as summary of changes

● max 50 characters

● begin with a capital letter

Page 12: Keep you GIT history clean

First line as summary of changes

● max 50 characters

● begin with a capital letter

● no period at the end

Page 13: Keep you GIT history clean

First line as summary of changes

● max 50 characters

● begin with a capital letter

● no period at the end

● imperative mood

Page 14: Keep you GIT history clean

Detailed description

● empty line

Page 15: Keep you GIT history clean

Detailed description

● empty line

● “what”, “why” not “how”

Page 16: Keep you GIT history clean

Detailed description

● empty line

● “what”, “why” not “how”

● wrap at 72 characters

Page 17: Keep you GIT history clean

Detailed description

● empty line

● “what”, “why” not “how”

● wrap at 72 characters

● markup syntax

Page 18: Keep you GIT history clean

Examples of good git repositories

● Git (https://github.com/git/git/commits/master)

● Linux kernel (https://github.com/torvalds/linux/commits/master)

● Spring Boot (https://github.com/spring-projects/spring-boot/commits/master)

Page 19: Keep you GIT history clean
Page 20: Keep you GIT history clean

> git commit --amend

Modifying last commit

Page 21: Keep you GIT history clean
Page 22: Keep you GIT history clean

Undo last commits

> git reset HEAD~1

Page 23: Keep you GIT history clean

Undo last commits

> git reset HEAD~1

Page 24: Keep you GIT history clean

Undo last commits

> git reset HEAD~1

> git reset --hard HEAD~1

Page 25: Keep you GIT history clean
Page 26: Keep you GIT history clean

Undo commit

> git revert <commit>

Page 27: Keep you GIT history clean

Undo commit

> git revert <commit>

Page 28: Keep you GIT history clean

Three-way merge

C1 C5C2

C3 C4

C6

feature

master

Page 29: Keep you GIT history clean

Three-way merge

C1 C5C2

C3 C4

C6

feature

C7

master

Page 30: Keep you GIT history clean

Rebasing

C1 C5C2

master

C3 C4

C6

feature

Page 31: Keep you GIT history clean

Rebasing

C1 C5C2

master

C6

> git rebase master

C3' C4'

feature

C3 C4

feature

Page 32: Keep you GIT history clean

Rebasing

C1 C5C2

master

C6

> git rebase master

C3' C4'

feature

C3 C4

feature

Page 33: Keep you GIT history clean

Interactive rebasing

> git rebase -i HEAD~5

Page 34: Keep you GIT history clean
Page 35: Keep you GIT history clean

Interactive rebasingmodifying commit message

pick a2936e8 commit 1reword 8f6e450 commit 2pick dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5

Page 36: Keep you GIT history clean

Interactive rebasingediting commit

pick a2936e8 commit 1pick 4ef5850 new messageedit dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5

Page 37: Keep you GIT history clean

Rebasing

> git rebase --skip

> git rebase --continue

> git rebase --abort

Page 38: Keep you GIT history clean

Interactive rebasingremoving commit

pick a2936e8 commit 1pick 4ef5850 new messagepick dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5

Page 39: Keep you GIT history clean

Interactive rebasingremoving commit

pick a2936e8 commit 1pick 4ef5850 new messagepick dabb0ef commit 3

pick 4df80af commit 5

Page 40: Keep you GIT history clean

Interactive rebasingsquash commits

pick a2936e8 commit 1pick 4ef5850 new messagesquash a733bfe edited commit pick 4df80af commit 5

Page 41: Keep you GIT history clean

Interactive rebasingfixup commit

pick a2936e8 commit 1pick e95fadc squashed commit pick 4df80af commit 5fixup 865ef03 commit 6pick 4ee98c2 commit 7

Page 42: Keep you GIT history clean

Interactive rebasingfixup commit

pick a2936e8 commit 1fixup 865ef03 commit 6pick e95fadc squashed commit pick 4df80af commit 5pick 4ee98c2 commit 7

Page 43: Keep you GIT history clean

Interactive rebasingrunning shell command

pick 37ef6a3 commit 1pick e95fadc squashed commit exec make testpick 4df80af commit 5exec cd subdir; make testpick 4ee98c2 commit 7

Page 44: Keep you GIT history clean

Fixup commit

> git commit --fixup=4df80af

Page 45: Keep you GIT history clean

Fixup commit

> git rebase -i --autosquash HEAD~5

pick a2936e8 commit 1pick e95fadc squashed commit pick 4df80af commit 5fixup 723de73 fixup! commit 5 pick 4ee98c2 commit 7

Page 46: Keep you GIT history clean

Squash commit

> git commit --squash=a2936e8

Page 47: Keep you GIT history clean

Squash commit

> git rebase -i --autosquash HEAD~5

pick a2936e8 commit 1squash 723de73 squash! commit 1 pick e95fadc squashed commit pick 4df80af commit 5pick 4ee98c2 commit 7

Page 48: Keep you GIT history clean
Page 49: Keep you GIT history clean

Reflog

> git reflog

8a8fa91 HEAD@{0}: merge branch1: Merge made by the 'recursive' strategy.ddae7c1 HEAD@{1}: checkout: moving from branch1 to master50465c0 HEAD@{2}: commit: Commit 4ddae7c1 HEAD@{3}: commit: Commit 3f15e834 HEAD@{4}: commit: My commit 24df80af HEAD@{5}: checkout: moving from master to branch14df80af HEAD@{6}: commit (initial): My first commit

Page 50: Keep you GIT history clean

Reflog

> git reset --hard HEAD@{3}

Page 51: Keep you GIT history clean

IDE vs terminal

Page 52: Keep you GIT history clean

Git log - filtering

> git log <origin>..<branch>

Page 53: Keep you GIT history clean

Git log - filtering

> git log --grep <search>

> git log <origin>..<branch>

Page 54: Keep you GIT history clean

Git log - filtering

> git log --grep <search>

> git log --before <date>

> git log <origin>..<branch>

Page 55: Keep you GIT history clean

Git log - filtering

> git log --grep <search>

> git log --before <date>

> git log --after <date>

> git log <origin>..<branch>

Page 56: Keep you GIT history clean

Git log - filtering

> git log --grep <search>

> git log --before <date>

> git log --after <date>

> git log --author <author name>

> git log <origin>..<branch>

Page 57: Keep you GIT history clean

Git log - formating

> git log

Page 58: Keep you GIT history clean

Git log - formating

> git log

> git log --oneline

Page 59: Keep you GIT history clean

Git log - formating

> git log

> git log --oneline

> git log --graph

Page 60: Keep you GIT history clean

Git log - formating

> git log

> git log --oneline

> git log --graph

> git log --decorate

Page 61: Keep you GIT history clean

Git log - formating

> git log

> git log --oneline

> git log --graph

> git log --decorate

> git log --oneline --graph --decorate

Page 62: Keep you GIT history clean
Page 63: Keep you GIT history clean

Thank you!