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

Keep your GIT history clean

Embed Size (px)

Citation preview

Page 1: Keep your GIT history clean

Keep your GIT history clean

Tomasz Brodziński

@TomaszBro

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

Commit message – formating and limitations

Page 4: Keep your 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 5: Keep your GIT history clean

Detailed description

● empty line

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

● wrap at 72 characters

● markup syntax

Page 6: Keep your 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 7: Keep your GIT history clean
Page 8: Keep your GIT history clean

> git commit --amend

Modifying last commit

Page 9: Keep your GIT history clean
Page 10: Keep your GIT history clean

Undo last commits

> git reset <commit>

> git reset --hard <commit>

Page 11: Keep your GIT history clean
Page 12: Keep your GIT history clean

Undo commit

> git revert <commit>

Page 13: Keep your GIT history clean

Three-way merge

C1 C5C2

C3 C4

C6

feature

C7

master

Page 14: Keep your GIT history clean

Rebasing

C1 C5C2

master

C3 C4

C6

feature

Page 15: Keep your GIT history clean

Rebasing

C1 C5C2

master

C6

> git rebase master

C3' C4'

feature

C3 C4

feature

Page 16: Keep your GIT history clean

Interactive rebasing

> git rebase -i HEAD~5

Page 17: Keep your GIT history clean
Page 18: Keep your GIT history clean

Interactive rebasingmodifying commit message

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

Page 19: Keep your GIT history clean

Interactive rebasingediting commit

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

Page 20: Keep your GIT history clean

Rebasing

> git rebase --skip

> git rebase --continue

> git rebase --abort

Page 21: Keep your GIT history clean

Interactive rebasingremoving commit

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

Page 22: Keep your GIT history clean

Interactive rebasingsquash commits

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

Page 23: Keep your GIT history clean

Interactive rebasingfixup commit

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

Page 24: Keep your GIT history clean

Interactive rebasingfixup commit

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

Page 25: Keep your 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 26: Keep your GIT history clean

Fixup commit

> git commit --fixup=4df80af

Page 27: Keep your 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 28: Keep your GIT history clean

Squash commit

> git commit --squash=a2936e8

Page 29: Keep your 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 30: Keep your GIT history clean
Page 31: Keep your 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 32: Keep your GIT history clean

Reflog

> git reset --hard HEAD@{3}

Page 33: Keep your GIT history clean

IDE vs terminal

Page 34: Keep your 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 35: Keep your GIT history clean

Git log - formating

> git log

> git log --oneline

> git log --graph

> git log --decorate

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

Page 36: Keep your GIT history clean
Page 37: Keep your GIT history clean

Thank you!