Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Git merge-base

Harri Kirik
September 02, 2019

Git merge-base

How git merge-base is awesome and can help you out in difficult situations.

Harri Kirik

September 02, 2019
Tweet

More Decks by Harri Kirik

Other Decks in How-to & DIY

Transcript

  1. DEMODAY git merge-base dive deeper Location, DD/MM/YYYY Name Surname, job

    title Title of the talk Git merge-base September 2nd, 2019 YOU SHOULD UNDERSTAND AND USE
  2. DEMODAY git merge-base git merge-base finds the best common ancestor

    between two commits to use in a three-way merge. 02
  3. DEMODAY git merge-base Ancestor is a parent or a parent

    of a parent (grandparent) or a great-grandparent, or a great-great-grandparent and so forth 03
  4. DEMODAY git merge-base One common ancestor X is better than

    another common ancestor Y if Y is an ancestor of X. 04
  5. DEMODAY git merge-base A common ancestor that does not have

    any better common ancestor is a best common ancestor, i.e. a merge base. 05
  6. DEMODAY git merge-base “git merge-base A B” is 1: 07

    o---o---o---B / ---2---1---o---o---o---A
  7. DEMODAY git merge-base Then the first commit (A) is the

    first argument, other commits (B C) will be merged* to create a second argument. 09
  8. DEMODAY git merge-base “git merge-base A B C” is 1:

    010 o----o----o----o----C / o----o----o----B / / ---2----1----o----o----o----A
  9. DEMODAY git merge-base For developing a fix to a release

    and dev branches at the same time. 013
  10. DEMODAY git merge base Something has gone wrong with the

    release We need to fix it fast! IMAGINE THAT 014
  11. DEMODAY git merge-base 1. ASAP: Fix the release 2. Merge

    the fix to dev so development can continue 015
  12. DEMODAY git merge-base 1. Create a fix branch at a

    merge base > git checkout -b fix-x $(git merge-base develop release-x) 017
  13. DEMODAY git merge-base 2. Fix the in fix-x branch 3.

    At release-x merge in the fix > git merge fix-x 4. Create and release another binary 5. At dev merge in the fix > git merge fix-x 019
  14. DEMODAY git merge-base Everything would still be fine even if

    these branches would be merged between themselves. 023
  15. DEMODAY git merge-base PS: Avoid cherry-picking like the plague! It

    makes magic happen. When you least expect it .. 025
  16. DEMODAY git merge-base 028 git merge-base finds best common ancestor(s)

    between two commits to use in a three-way merge.
  17. DEMODAY git merge-base 032 .. amount = 15; .. ..

    amount = 3; .. File A File B .. amount = 3; .. Common ancestor