Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Why doesn't git diff show any differences?

If I run 'git status' on my repo it gives:

# On branch master # Changes to be committed: #   (use "git reset HEAD <file>..." to unstage) # #   modified: myfile 

However, if I do a 'git diff myfile' it shows no differences. Is this because I have made a change and removed it so it is back to the original?

Should I run 'git checkout myfile' to clear it?

like image 362
Noam Avatar asked Jan 19 '11 11:01

Noam


People also ask

Why is git diff not showing anything?

In answer to the original question, git diff isn't showing anything because you have a brand new directory, with a newly added file, but there are zero changes in the file for git diff to show. git status is showing that you added a new file, but git diff is for showing changes within files.

How do I see changes in git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

How does git diff work?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

What is the command to check diff in git?

The git diff command allows us to compare different versions of branches and repository. To get the difference between branches, run the git diff command as follows: $ git diff <branch 1> < branch 2>


1 Answers

Your file is already staged to be committed. You can show it's diff using the --cached option of git.

git diff --cached myfile 

To unstage it, just do what git status suggests in it's output ;)

You can check The Git Index For more info.

like image 163
Marcus Borkenhagen Avatar answered Sep 20 '22 06:09

Marcus Borkenhagen