Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git status shows modified files, but git diff shows nothing

Tags:

git

I have done "git reset --soft HEAD^" to get rid of some files from commit, but I have some problems.

Command "git status" shows list of files (modified -- green). But if I want to shows changes with command "git diff" git shows nothing. Also when I trying revert changes by "git checkout <FILE>" it gives no result.

If I open any of these files I see my changes.

like image 489
Marcin Avatar asked Apr 03 '15 07:04

Marcin


People also ask

Why git diff does not show changes?

Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.

Why does git show that all my files changed when I didn't change them?

These changes mean that metadata about your file changed, however the content of your file did not. If you're working in a group, this may start to intefere with pushes or just add noise to your commits.

What is the difference between the git diff and git status?

The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.

Does git diff show all changes?

The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.


1 Answers

I have done "git reset --soft HEAD^" to get rid of some files from commit, but I have some problems. Command "git status" shows list of files (modified -- green).

This expected behavior according to documentation:

--soft

Does not touch the index file or the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

In future use --mixed flag to move files to not-staged area

git reset --mixed HEAD^

OR just:

git reset HEAD^

because --mixed is used by default


The current situation may be fixed by:

git reset HEAD -- <file>

This will make a file unstaged. Or without -- <file to apply to all files.

Or use git diff --cached to show diff of staged files.


Also when I trying revert changes by "git checkout " it gives no result.

git checkout <FILE> works if file is unstaged.

like image 179
phts Avatar answered Sep 22 '22 10:09

phts