Git – how to view diff for a given commit id

Diff commit id with its first parent commit id

Here are some approaches to view diff between first parent of commit id and commit id. We’ll use 6680c1b29ea79bf33ac6bd31578755c7c514ed3e as commit for the purpose of this article.

  1. Using git diff

    $ git diff 6680c1b29ea79bf33ac6bd31578755c7c514ed3e^ 6680c1b29ea79bf33ac6bd31578755c7c514ed3e
    //or
    $ git diff 6680c1b29ea79bf33ac6bd31578755c7c514ed3e^!
    
  2. Using git diff-tree

    $ git diff-tree -p 6680c1b29ea79bf33ac6bd31578755c7c514ed3e
    
  3. Using git show

    $ git show --color --pretty=format:%b 6680c1b29ea79bf33ac6bd31578755c7c514ed3e
    

Diff a commit id with repository head

$ git diff 6680c1b29ea79bf33ac6bd31578755c7c514ed3e

Diff of head commit

$ git diff HEAD^ HEAD 

Example showing diff of a commit id

Follow these steps to see the diff of a commit id.

  1. Clone any git repository. We’ll clone jquery repository.

    $ git clone https://github.com/jquery/jquery
    $ cd jquery
    
  2. Run git log to view some recent commit ids. Run the following command for view diff for a commit id (6680c1b29ea79bf33ac6bd31578755c7c514ed3e).

    $ git diff 6680c1b29ea79bf33ac6bd31578755c7c514ed3e^ 6680c1b29ea79bf33ac6bd31578755c7c514ed3e
    

    Here is initial portion of the outcome.

    diff --git a/src/attributes/attr.js b/src/attributes/attr.js
    index ae48676..00b0848 100644
    --- a/src/attributes/attr.js
    +++ b/src/attributes/attr.js
    @@ -7,7 +7,14 @@ define( [
     ], function( jQuery, access, support, rnotwhite ) {
     
     var boolHook,
    -       attrHandle = jQuery.expr.attrHandle;
    +       attrHandle = jQuery.expr.attrHandle,
    
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments