56
@movetodevnull sebastianfeldmann Everybody is git fu Developing

Everybody is git fu Developing - sebastian-feldmann.info · Merge pull request #67 from pille/fix-spocks-shit Fix spocks shit Mc Coy commented out failing tests Mr Spock - Temporary

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

  • @movetodevnullsebastianfeldmann

    Everybody

    is git fu

    Developing

    https://twitter.com/movetodevnullhttps://github.com/sebastianfeldmann

  • @movetodevnull

    ~ 30 years

    About me

    https://twitter.com/movetodevnull

  • It’s working!Mc Coy

    minor changesMr Spock

    Fixed TpyoMc Coy

    for real 4 real this timeSkotty

    fix bug, for realzSkotty

    fixed bugScotty

    added security.Lt Worf

    Merge pull request #67 from pille/fix-spocks-shit Fix spocks shitMc Coy

    commented out failing testsMr Spock

    - Temporary commit.James T. Kirk

    Debug suff

  • Atomic Commits

  • Implemented new voting feature, fixed an internal messaging issue and refactored some inheritance menace

    Add voting api endpoints and actions

    Fix internal messaging issue

    Refactor Formatters to be composable

    Add voting persistence services

    atomic commits

  • Rules

    • Single irreducible useful set of changes

    • Everything works

    • No „and“ in commit message subjects

  • Commit Messages

  • whatthecommit.com

    • Major fixup

    • Fixed tpyo

    • One does not simply merge into master

    • Best commit ever

  • Rules

    • Separate subject from body with one blank line

    • Limit the subject line to 50 characters

    • Do not end the subject line with a period

    • Capitalize the subject line

    • Use imperative mood for the subject line

    • Wrap the body at 72 characters

    • Use the body to explain what and why vs. how

  • Subject Line

  • Subject Line

    Use the imperative mood for the subject line
like git is doing it

    Mergebranch'myfeature'

    Always complete the following: If applied, this commit will your subject line here

  • Subject Examples

    Merge branch 'feature-x'

    Update the getting started documentation

    Remove all deprecated methods

    Prepare version 1.0.0

    Fixed bug #123

    Changing behavior of X

    More fixes for broken stuff

    Added sweet new API methods

    this commit will

    this commit will

    this commit will

    this commit will

  • Full Example

    Summarizechangesinaround50charactersorless

    Moredetailedexplanatorytext,ifnecessary.Wrapittoabout72charactersorso.Insomecontexts,thefirstlineistreatedasthesubjectofthecommitandtherestofthetextasthebody.Theblanklineseparatingthesummaryfromthebodyiscritical(unlessyouomitthebodyentirely);varioustoolslike`log`,`shortlog`and`rebase`cangetconfusedifyourunthetwotogether.

    Explaintheproblemthatthiscommitissolving.Focusonwhyyouaremakingthischangeasopposedtohow(thecodeexplainsthat).Aretheresideeffectsorotherunintuitiveconsequensesofthischange?Here'stheplacetoexplainthem.

    Furtherparagraphscomeafterblanklines.

    -Bulletpointsareokay,too

    -Typicallyahyphenorasteriskisusedforthebullet,precededbyasinglespace,withblanklinesinbetween,butconventionsvaryhere

    Ifyouuseanissuetracker,putreferencestothematthebottom,likethis:

    Resolves:#123Seealso:#456,#789

  • gitare herogit Graph

  • git GRAPH

    Your mind is like this git graph my friend. When it is agitated it becomes difficult to see but if you allow it to settle the answer becomes clear

    „–Master Oogway

  • git merge

    Merge remote-tracking branch ‘origin/master’„ „

    No big deal and completely safe, but still messes up the log history "a bit".

  • git merge

  • git merge

  • git merge

  • git rebase

  • git rebase

  • git rebase

  • git Log

    gitconfig--globalalias.integrate'!test"$(gitmerge-baseHEAD"$1")"="$(gitrev-parseHEAD)"&&gitmerge--no-ff--edit$1||echo>&2"Notup-to-date;refusingtomerge,rebasefirst!“

  • git rebase

    Ahh, but the bliss of rebasing isn’t without its drawbacks, which can be summed up in a single line:

    Do not rebase commits that exist outside your repository

    If you follow that guideline, you’ll be fine. If you don’t, people will hate you, and you’ll be scorned by friends and family.

    –git book

  • git Rebase

    $ gitrebase-i

  • git Rebase

    pick3e11d0dAddsuperheropersistencelayerpick279be79Addsuperherofightingskillspickfc6d26fAddsuperheropublicapipickeb3da88Fixtypo

    #Commands:#p,pick=usecommit#r,reword=usecommit,buteditthecommitmessage#e,edit=usecommit,butstopforamending#s,squash=usecommit,butmeldintopreviouscommit#f,fixup=like"squash",butdiscardthiscommit'slogmessage#x,exec=runcommand(therestoftheline)usingshell#b,break=stophere(continuerebaselaterwith'gitrebase--continue')#d,drop=removecommit#l,label=labelcurrentHEADwithaname#t,reset=resetHEADtoalabel#m,merge[-C|-c][#]#.createamergecommitusingtheoriginalmergecommit's#.message(ortheoneline,ifnooriginalmergecommitwas#.specified).Use-ctorewordthecommitmessage.

  • git Rebase

    pick3e11d0dAddsuperheropersistencelayerpick279be79Addsuperherofightingskillspickfc6d26fAddsuperheropublicapi

    #Commands:#p,pick=usecommit#r,reword=usecommit,buteditthecommitmessage#e,edit=usecommit,butstopforamending#s,squash=usecommit,butmeldintopreviouscommit#f,fixup=like"squash",butdiscardthiscommit'slogmessage#x,exec=runcommand(therestoftheline)usingshell#b,break=stophere(continuerebaselaterwith'gitrebase--continue')#d,drop=removecommit#l,label=labelcurrentHEADwithaname#t,reset=resetHEADtoalabel#m,merge[-C|-c][#]#.createamergecommitusingtheoriginalmergecommit's#.message(ortheoneline,ifnooriginalmergecommitwas#.specified).Use-ctorewordthecommitmessage.

  • git Rebase

    pick3e11d0dAddsuperheropersistencelayerpick279be79Addsuperherofightingskillspickeb3da88Fixtypopickfc6d26fAddsuperheropublicapi

    #Commands:#p,pick=usecommit#r,reword=usecommit,buteditthecommitmessage#e,edit=usecommit,butstopforamending#s,squash=usecommit,butmeldintopreviouscommit#f,fixup=like"squash",butdiscardthiscommit'slogmessage#x,exec=runcommand(therestoftheline)usingshell#b,break=stophere(continuerebaselaterwith'gitrebase--continue')#d,drop=removecommit#l,label=labelcurrentHEADwithaname#t,reset=resetHEADtoalabel#m,merge[-C|-c][#]#.createamergecommitusingtheoriginalmergecommit's#.message(ortheoneline,ifnooriginalmergecommitwas#.specified).Use-ctorewordthecommitmessage.

  • git Rebase

    pick3e11d0dAddsuperheropersistencelayerpick279be79Addsuperherofightingskillseb3da88Fixtypopickfc6d26fAddsuperheropublicapi

    #Commands:#p,pick=usecommit#r,reword=usecommit,buteditthecommitmessage#e,edit=usecommit,butstopforamending#s,squash=usecommit,butmeldintopreviouscommit#f,fixup=like"squash",butdiscardthiscommit'slogmessage#x,exec=runcommand(therestoftheline)usingshell#b,break=stophere(continuerebaselaterwith'gitrebase--continue')#d,drop=removecommit#l,label=labelcurrentHEADwithaname#t,reset=resetHEADtoalabel#m,merge[-C|-c][#]#.createamergecommitusingtheoriginalmergecommit's#.message(ortheoneline,ifnooriginalmergecommitwas#.specified).Use-ctorewordthecommitmessage.

  • git Rebase

    pick3e11d0dAddsuperheropersistencelayerpick279be79Addsuperherofightingskillsfixupeb3da88Fixtypopickfc6d26fAddsuperheropublicapi

    #Commands:#p,pick=usecommit#r,reword=usecommit,buteditthecommitmessage#e,edit=usecommit,butstopforamending#s,squash=usecommit,butmeldintopreviouscommit#f,fixup=like"squash",butdiscardthiscommit'slogmessage#x,exec=runcommand(therestoftheline)usingshell#b,break=stophere(continuerebaselaterwith'gitrebase--continue')#d,drop=removecommit#l,label=labelcurrentHEADwithaname#t,reset=resetHEADtoalabel#m,merge[-C|-c][#]#.createamergecommitusingtheoriginalmergecommit's#.message(ortheoneline,ifnooriginalmergecommitwas#.specified).Use-ctorewordthecommitmessage.

  • git Rebase

    Successfullyrebasedandupdatedrefs/heads/superhero-feature$ gitlog--onlinefc6d26f(HEAD->superhero-feature)Addsuperheropublicapi279be79Addsuperherofightingskills3e11d0dAddsuperheropersistencelayer71f3681(master)Latestmasterstatea51d619Somenewmastercommits...

  • git reflog

    $ gitreflog

  • git beflog

    31025a0(HEAD->feature-x)HEAD@{0}:Addsuperfeature31025a0(HEAD->feature-x)HEAD@{1}:rebase-i(fixup):Addbarfunctionfc6d26fHEAD@{2}:rebase-i(start):checkoutmasterbae0d58HEAD@{3}:commit:Dosomethingeb3da88HEAD@{4}:commit(amend):Fixtypod5db54cHEAD@{5}:commit:Fixtpyo...

  • git Beflog

    $ gitresetHEAD@{4}$

  • Force push

    $ git push --force-with-lease

  • Git HOOKS

  • Hooks

    • commit-msg

    • post-checkout

    • post-merge

    • pre-commit

    • pre-push

    • pre-receive

    • update

    • post-receive

    Local Remote

  • Problems

    • Not activated by default

    • Manual install

    • Execution may system dependent (bash)

    • Difficult to share hooks cross project or cross team

  • CaptainHookPHP/captainhook

  • Configuration

    { "commit-msg": {"enabled": true...}, "pre-commit": {"enabled": true...}, "pre-push": {"enabled": false...} }

    +

    +

    +

  • Configuration

    { "commit-msg": { "enabled": true, "actions": [ { "action": „\\CaptainHook\\App\\Hook\\Message\\Action\\Beams", "options": { "subjectLength": 50, "bodyLineLength": 72 } } ] }, "pre-commit": {"enabled": true...}, "pre-push": {"enabled": false...} }

    -

    +

    +

  • Configuration

    { "commit-msg": {"enabled": true...}, "pre-commit": {"enabled": true...}, "pre-push": {"enabled": false…} }

    +

    +

    +

  • Configuration

    { "commit-msg": {"enabled": true...}, "pre-commit": { "enabled": true, "actions": [ { "action": „\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting", "options": [] }, { "action": "phpcs --standard=psr2 src", "options": [] } ] }, "pre-push": {"enabled": false...} }

    -

    +

    +

  • Configuration

    { "commit-msg": {"enabled": true...}, "pre-commit": { "enabled": true, "actions": [ { "action": „\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting", "options": [] }, { "action": "phpcs --standard=psr2 src", "options": [] }

    ] }, "pre-push": {"enabled": false...} }

    -

    +

    +

  • Configuration

    { "commit-msg": {"enabled": true...}, "pre-commit": { "enabled": true, "actions": [ { "action": "\\CaptainHook\\App\\Hook\\PHP\\Action\\Linting", "options": [] }, { "action": "phpcs --standard=psr2 src", "options": [] }, { "action": „\\CaptainHook\\App\\Hook\\PHP\\Action\\TestCoverage", "options": { "minCoverage": 75 } } ] }, "pre-push": {"enabled": false...} }

    -

    +

    +

  • demo

  • Extend

    • Commit message "Rules"

    • Custom Actions

    • Static methods

    • Commands

  • Rules

  • Rules

    { "commit-msg": { "enabled": true, "actions": [ { "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Rules", "options": [ "\\Acme\\GitHook\\DoNotYell" ] } ] } }

    -

    sebastianfeldmann/captainhook

    https://github.com/sebastianfeldmann/captainhook

  • Rules

    { "commit-msg": { "enabled": true, "actions": [ { "action": „\\CaptainHool\\App\\Hook\\Message\\Action\\Rules", "options": [ "\\Acme\\GitHook\\DoNotYell", "\\CaptainHook\\App\\Hook\\Message\\Rule\\SubjectStartsWithCapitalLetter" ] } ] } }

    -

  • Actions

  • Actions

  • Actions

    { "commit-msg": { "enabled": true, "actions": [ { "action": „\\Acme\\GitHook\\TicketIDValidator“, "options": { "key": "value", "use": "what you need" } } ] } }

    -

  • Existing Plugins

    • bitExpert/captainhook-validateauthor

    • bitExpert/captainhook-rejectpush

  • thank

    you