Date post: | 15-Apr-2017 |
Category: |
Technology |
Upload: | tomasbro |
View: | 187 times |
Download: | 0 times |
Keep your GIT history clean
Tomasz Brodziński
@TomaszBro
Commit message – formating and limitations
First line as summary of changes
● max 50 characters
● begin with a capital letter
● no period at the end
● imperative mood
Detailed description
● empty line
● “what”, “why” not “how”
● wrap at 72 characters
● markup syntax
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)
> git commit --amend
Modifying last commit
Undo last commits
> git reset <commit>
> git reset --hard <commit>
Undo commit
> git revert <commit>
Three-way merge
C1 C5C2
C3 C4
C6
feature
C7
master
Rebasing
C1 C5C2
master
C3 C4
C6
feature
Rebasing
C1 C5C2
master
C6
> git rebase master
C3' C4'
feature
C3 C4
feature
Interactive rebasing
> git rebase -i HEAD~5
Interactive rebasingmodifying commit message
pick a2936e8 commit 1reword 8f6e450 commit 2pick dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5
Interactive rebasingediting commit
pick a2936e8 commit 1pick 4ef5850 new messageedit dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5
Rebasing
> git rebase --skip
> git rebase --continue
> git rebase --abort
Interactive rebasingremoving commit
pick a2936e8 commit 1pick 4ef5850 new messagepick dabb0ef commit 3pick ef5a182 commit 4pick 4df80af commit 5
Interactive rebasingsquash commits
pick a2936e8 commit 1pick 4ef5850 new messagesquash a733bfe edited commit pick 4df80af commit 5
Interactive rebasingfixup commit
pick a2936e8 commit 1pick e95fadc squashed commit pick 4df80af commit 5fixup 865ef03 commit 6pick 4ee98c2 commit 7
Interactive rebasingfixup commit
pick a2936e8 commit 1fixup 865ef03 commit 6pick e95fadc squashed commit pick 4df80af commit 5pick 4ee98c2 commit 7
Interactive rebasingrunning shell command
pick 37ef6a3 commit 1pick e95fadc squashed commit exec make testpick 4df80af commit 5exec cd subdir; make testpick 4ee98c2 commit 7
Fixup commit
> git commit --fixup=4df80af
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
Squash commit
> git commit --squash=a2936e8
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
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
Reflog
> git reset --hard HEAD@{3}
IDE vs terminal
Git log - filtering
> git log --grep <search>
> git log --before <date>
> git log --after <date>
> git log --author <author name>
> git log <origin>..<branch>
Git log - formating
> git log
> git log --oneline
> git log --graph
> git log --decorate
> git log --oneline --graph --decorate
Thank you!