$30 off During Our Annual Pro Sale. View Details »

Git beyond commit - keep your history clean

Yannick Baron
October 18, 2022
28

Git beyond commit - keep your history clean

Mergen Sie noch oder Rebasen Sie schon? In dieser Session schauen wir uns ein
paar Tricks mit git an, mit dem Ziel die git History sauber und lesbar zu halten.
Hier findet vieles Anwendung, was über das übliche Commiten und Pushen in der IDE hinausgeht. Themen wie Interactive Rebase, fixup, autosquash und das Splitten von Hunks finden hier unter anderem seinen Platz.
Je nach Lust und Laune sind auch Abstecher in andere Themen denkbar.

Yannick Baron

October 18, 2022
Tweet

More Decks by Yannick Baron

Transcript

  1. Git - beyond commit
    keep your history clean
    Yannick Baron
    @yannick_baron
    Software Architecture Consultant

    View Slide

  2. "Git is easy"

    View Slide

  3. Clone the repository


    "Git is easy"

    View Slide

  4. Clone the repository


    Make changes


    "Git is easy"

    View Slide

  5. Clone the repository


    Make changes


    Mess things up


    "Git is easy"

    View Slide

  6. Clone the repository


    Make changes


    Mess things up


    Look at StackOver
    fl
    ow and copy an obscure command


    "Git is easy"

    View Slide

  7. Clone the repository


    Make changes


    Mess things up


    Look at StackOver
    fl
    ow and copy an obscure command


    Mess things up even more


    "Git is easy"

    View Slide

  8. Clone the repository


    Make changes


    Mess things up


    Look at StackOver
    fl
    ow and copy an obscure command


    Mess things up even more


    Delete folder


    "Git is easy"

    View Slide

  9. Clone the repository


    Make changes


    Mess things up


    Look at StackOver
    fl
    ow and copy an obscure command


    Mess things up even more


    Delete folder


    Clone the repository


    ...
    "Git is easy"

    View Slide

  10. https://stackover
    fl
    ow.com/questions?tab=Votes

    View Slide

  11. https://stackover
    fl
    ow.com/questions?tab=Votes

    View Slide

  12. The core of git

    View Slide

  13. • The git history is a graph, a tree to be precise


    • A node in that tree is the state of our
    fi
    les at a point in time


    • Most operations deal with how to navigate and manipulate that tree
    The git history

    View Slide

  14. Tree Interlude?

    View Slide

  15. • Understand the evolution of the project (history, communication)


    • Rollback to (or revert / redo) previous change


    • Find or compare to previously working code


    • Find which change introduced an error


    • Understand when development paths divert and see potential con
    fl
    ict


    • ...


    Uses of the git history

    View Slide

  16. • Understand the evolution of the project (history, communication)


    • Rollback to (or revert / redo) previous change


    • Find or compare to previously working code


    • Find which change introduced an error


    • Understand when development paths divert and see potential con
    fl
    ict


    • ...


    A clean history keeps things readable, traceable and makes integration of
    changes easier


    Uses of the git history

    View Slide

  17. Chaos vs Unity

    View Slide

  18. Embrace Rebase

    View Slide

  19. main
    feat feat
    main
    Simple Merge

    View Slide

  20. main
    feat feat
    main
    feat
    main
    Late Merge

    View Slide

  21. main
    feat
    main
    feat
    Control Merge
    main
    feat

    View Slide

  22. main
    feat
    main
    feat
    Control Merge
    feat
    main
    feat2

    View Slide

  23. main
    feat
    main
    feat
    main
    feat
    Rebase

    View Slide

  24. Why do control merges happen?

    View Slide

  25. But rebase is evil because force push is evil and loses data

    View Slide

  26. BuT rEbAsE iS eViL bEcAuSe fOrCe pUsH iS eViL aNd LoSeS dAtA

    View Slide

  27. But rebase is evil because force push is evil and loses data
    git push --force-with-lease git push --force-if-includes

    View Slide

  28. git add -p
    git commit --amend [--no-edit]
    git commit --fixup 

    git rebase -i --autosquash
    Tricks to keep the history clean

    View Slide

  29. Interactive Rebase

    View Slide


  30. fi
    xup


    • squash


    • reordering


    • editing past commits


    • rewording


    • ...
    Interactive Rebase

    View Slide

  31. It's a wrap!
    [email protected]

    • https://www.thinktecture.com/thinktects/yannick-baron

    View Slide

  32. git bisect start
    git bisect bad
    git bisect good []
    Bonus: Bisect

    View Slide

  33. git worktree add []
    git worktree list
    git worktree remove
    Bonus: Worktrees

    View Slide