git - diff of current changes before committing

GitSshDiffMeld

Git Problem Overview


I have changed several files in a git repository, but have not committed them yet.

I can get a list of the changes by just invoking git status. But how do I get a listing of the lines or the content that I have changed, in addition to the filenames?

I initially thought about using git diff, but it seems to be useful only for comparing already commited changes.

Usually I just do meld ., but on this case I'm connected to an external server via ssh.

Git Solutions


Solution 1 - Git

git diff by default shows difference between your working directory and the index (staging area for the next commit).

If you have already added (staged) the changes to the staging area, git diff --staged does the job. Staging area is the data from which the next commit will be formed by git commit.

P. S. Good reading (IMO) for Git beginners:

Solution 2 - Git

What i use for such cases is:

git diff HEAD *

This will show the changes since last commit. Although somehow it works quicker with

git diff .

or

git diff

To see the changes on previously git added files, use the staged flag:

git diff --staged

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionkikitoView Question on Stackoverflow
Solution 1 - GitMischa ArefievView Answer on Stackoverflow
Solution 2 - GitEliuXView Answer on Stackoverflow