tags:

views:

123

answers:

4

How can you show the differences of a file in the last 5 commits to the current uncommitted file by Git-show?

I made a change to my file which breaks my code. However, I do not know where the change is.

I would like to compare the current uncommitted files to the recent commit (HEAD), to the previous commit (^HEAD) and at least 3 commits deeper.

However, I do not know how you can do it efficiently.

In trying to see the changes of the five last commits of one file to the current file in the given branch, I unsuccessfully ran

git show next~5:handle_questions.php
+2  A: 

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

Cody Caughlan
+3  A: 

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>
db_
+2  A: 

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

$ git diff HEAD~5 handle_questions.php
William Pursell
+1  A: 

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

SHA (Author Timestamp Line Number) code
Mike Tierney
This is a great command! Thank you for sharing it.
Masi