[ACCEPTED]-Comparing changes in commits to the current file by Git-git

Accepted answer
Score: 63

Here is my cheat-sheet:

# uncommited file to HEAD
git diff <path>

# uncommited file to before last commit
git diff HEAD^ -- <path>

#last commit to before last commit
git diff HEAD^ HEAD -- <path>

#difference between HEAD and n-th grandparent
git diff HEAD~n HEAD -- <path>

#Another cool feature is whatchanged command
git whatchanged -- <path>

0

Score: 4

To see the diff between handle_questions.php 2 in the working directory and in the repository 1 5 commits back, use:

$ git diff HEAD~5 handle_questions.php
Score: 3

You can use git bisect to track down the 1 commit which introduced a bug.

Score: 2

If you know the file that the change was 3 made in, you can also use git blame <path> - this will give 2 you ahistory of each line of code in the 1 following format:

SHA (Author Timestamp Line Number) code
Score: 0

From @db_ answer (but shown as an actual 3 example)

I just want to see what difference 2 there is between the current file and the 1 last commit for just a single file.

git diff scripts/processQueue.php


-  if( filemtime( $filename ) < time() - 10 ) {
+  $filemtime=filemtime($filename);
+  if( $filemtime < time() - 10 && $filemtime> (time() - 86400)) 

More Related questions