Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between the staged and unstaged versions of the same file, using difftool [duplicate]

Is there a way of viewing the differences between the staged and unstaged versions of the same file?

For example:

Changes to be committed:

    modified:   conf/application.conf

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   conf/application.conf

This happens when I stage a change and then I modify the file again, without staging it.

EDIT

The git status -vv command is not good enough, because I need to use the diff / difftool command. That's because in practice there are too many changes in too many files, and scrolling through all of them is not efficient. But diff / difftool allows me to specify the file I am interested in.

like image 289
DrKaoliN Avatar asked Dec 20 '16 15:12

DrKaoliN


People also ask

What is the difference between staged and unstaged changes?

Unstaged vs Staged changesUnstaged changes are changes that are not tracked by the Git. For example, if you copy a file or modify the file. Git maintains a staging area(also known as index) to track changes that go in your next commit.

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

git diff --staged will only show changes to files in the "staged" area. git diff HEAD will show all changes to tracked files. If you have all changes staged for commit, then both commands will output the same.

How can we see the difference between staging area and working directory?

Tracking changes between Staging Area, Working Directory, and the Previous Commit is done by git diff command.


2 Answers

git diff will show the difference between your workspace and the index. (the index is where the staged files live)

This may not seem obvious because we usually use git diff to see the changes in the workspace vs what is checked in. However, technically git diff shows workspace vs index, and if you haven't added changes to the index, then the index matches what you checked out.

  • to see workspace vs repo: git diff HEAD
  • to see index vs repos: git diff --cached (can also use --staged)
  • to see workspace vs index: git diff
like image 149
Randy Leberknight Avatar answered Sep 22 '22 03:09

Randy Leberknight


If you run the command git status -vv you will see the textual changes of the file. See doc.

like image 33
Jake Henningsgaard Avatar answered Sep 24 '22 03:09

Jake Henningsgaard