modern source and_version_control_with_git

27
 Modern Source and Version Control with Git November 2016 Christian Couder [email protected]

Upload: christian-couder

Post on 16-Apr-2017

92 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Modern source and_version_control_with_git

   

Modern Source and Version Control with Git

November 2016

Christian [email protected]

Page 2: Modern source and_version_control_with_git

   

A Distributed Version Control System (DVCS):

● created by Linus Torvalds

● maintained by Junio Hamano

● since 2005

● Most popular VCS (~30% of developers)

About Git

Page 3: Modern source and_version_control_with_git

   

● started developing Git in 2006

● worked especially on git bisect

● independent consultant working for Booking.com, 

GitLab and Protocol Labs

About myself

Page 4: Modern source and_version_control_with_git

   

● Evolution of version control with Git

● Benefits in terms of quality and agility 

The plan

Page 5: Modern source and_version_control_with_git

   

Easy to create and merge branches

● Before Git, branches were something “big”, slow 

and difficult to merge

● With Git, they are light and trivial

What is modern version control?

Page 6: Modern source and_version_control_with_git

   

Why it changes everything?

● We want to create and merge many branches

● And we want to manage and automate the process

● This means we need:

– Feature branches

– Pull requests

– Complex workflows (like Git Flow)

Page 7: Modern source and_version_control_with_git

   

Git Flow

Page 8: Modern source and_version_control_with_git

   

Two possible reactions

● That's awesome and very smart!

● Help! I am scared, it's just too complex and 

unmanageable!

Page 9: Modern source and_version_control_with_git

   

Let's keep history simple (stupid)!

We need something to linearize history!

=> git rebase is our friend

While at it, let's also merge or move or just remove 

commits!

=> git rebase ­i is our friend

Page 10: Modern source and_version_control_with_git

   

Let's go with a complex history!

● git log ­­decorate ­­oneline –graph

will help visualize it!

● git bisect will help find bad commits

– We can even automate it with: git bisect run

– We can skip untestable commits with:

git bisect skip

Page 11: Modern source and_version_control_with_git

   

Commits in Git form a DAG

(Directed Acyclic Graph)

●history direction is from left to right

●new commits point to their parents

Page 12: Modern source and_version_control_with_git

   

First Bad Commit

B

●B introduces a bad behavior called "bug" or "regression"

● red commits are called "bad"

●blue commits are called "good"

Page 13: Modern source and_version_control_with_git

   

In the end it all comes together

● When using git rebase and git bisect we realize that 

they work together very well 

● Let's take a look for example at code review and 

testing

Page 14: Modern source and_version_control_with_git

   

Why Code Review and Testing?

● They are the best way to improve: quality and agility

● Continuous Integration and Deployment rely on 

Code Review and Testing

Because you really don't want bugs in the product 

you give to your customer!

Page 15: Modern source and_version_control_with_git

   

Modern Code Review 1

● It's when you “polish” (rework) your commits until it is 

clear that they are all good.

● This means you want:

– small commits

– good commit messages (that explain why)

Page 16: Modern source and_version_control_with_git

   

Modern Code Review 2

git rebase ­i helps you rework commits:

● split them into smaller commits

● modify them and their commit message

Page 17: Modern source and_version_control_with_git

   

Modern Testing

● Think black box test too, not just unit tests

● Test each commit: git rebase ­­exec <cmd>

● 1 test at least for each new feature

● 1 test at least for each bug (fixed, or not)

Page 18: Modern source and_version_control_with_git

   

● 11 years ago Junio Hamano created the Git test 

framework (test­lib.sh)

● Developed in shell (POSIX /bin/sh compatible)

● Extracted 5 years ago by Mathias Lafeldt into a 

separate project called Sharness

● It's one of the main reasons why Git has always 

been very stable

Sharness

Page 19: Modern source and_version_control_with_git

   

Why 1 test for each new feature?

● It shows the feature has been at least minimally 

tested

● It documents the feature

● It makes the reviewer's job easier

● It makes it easier to add more tests later

Page 20: Modern source and_version_control_with_git

   

Why 1 test for each bug (fixed, or not)?

● It documents the bug

● It helps reproduce the bug

● It will make sure the bug will not reappear

● It makes the reviewer's job easier

● It's easy to do if there is already 1 test per feature

Page 21: Modern source and_version_control_with_git

   

Using a git bisect based Test Workflow

● Write the test for a bug before fixing the bug

● Use git bisect run mytest to automatically find the 

commit that introduced the bug  

● Fix the bug (which should be easier)

● Commit the bug fix and the test together

Page 22: Modern source and_version_control_with_git

   

Why a git bisect based test workflow?

● It make it easier to fix the bug

● Because it gives more accurate information

● It takes advantage of small commits

● It takes advantage of good commit messages

● People who have used it report great efficiency 

improvements

Page 23: Modern source and_version_control_with_git

   

To conclude

Hopefully you now know what can be a modern 

version control with Git, especially:

● The evolution it represents, and the logic of this 

evolution 

● The benefits, in terms of quality and agility, through 

better code reviews and testing

Page 24: Modern source and_version_control_with_git

   

Many thanks to:

● Junio Hamano, Linus Torvalds, Mathias Lafeldt

● many other great people in the Git and Linux communities

● Paris Open Source Summit organizers and attendants,

● Booking.com, GitLab and Protocol Labs, the companies I am working 

for.

Page 25: Modern source and_version_control_with_git

   

● http://www.slideshare.net/ChristianCouder/

● https://semmle.com/customers/github­change­impact/

● http://git­scm.com

● https://github.com/chriscool/sharness

● https://github.com/chriscool/sharnessify

Links

Page 26: Modern source and_version_control_with_git

   

Questions?

Page 27: Modern source and_version_control_with_git

   

Idea:

● help find a first bad commit

● use a binary search algorithm for efficiency if possible

 

Benefits:

● manually verifying the source code changes from only one commit is relatively easy

● the commit gives extra information: commit message, author, ... 

Git bisect