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

Understanding Diffs in Git

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.
Avatar for Tower Tower
April 30, 2014

Understanding Diffs in Git

Understanding "diffs" is crucial for understanding a project. Learn how to read and generate them in the Git version control system.

Avatar for Tower

Tower

April 30, 2014
Tweet

Other Decks in Programming

Transcript

  1. What a Diff Is <div id="headerContainer"> - <h1>Imprint</h1> + <h1>Imprint

    / Disclaimer</h1> </div> Diffs visualize modifications… …by comparing two versions of a file.
  2. How to Read a Diff Part I: The Basics <div

    id="headerContainer"> - <h1>Imprint</h1> + <h1>Imprint / Disclaimer</h1> </div> ! ! <span> - <a name=“top”>Home</a> </span> ! ! <li>Products</li> + <li>Contact Us</li> + <li>About Us</li> </ul> lines from version A of the file = “-“ lines from version B of the file = “+“ a diff doesn’t show all of a file but only the changed parts 
 (= “chunks”) some unchanged lines surround the change to provide a bit of context
  3. How to Read a Diff Part I: The Basics desktop

    apps like Tower also use colors (in addition to +/-) for clarity
  4. How to Generate Diffs in Git $ git log -p

    ! ! $ git diff ! ! $ git diff master..develop ! ! $ git diff 10a23e..fcd619 commit history with the “-p” flag includes “patch” (= diff) in the output unstaged local changes in your working copy compare branch “master” with “develop” compare revision “10a23e” with “fcd619”