3

I have a following problem. I want to get the output from git diff, but for all uncommitted local changes (that means unstaged and staged files).

I am not searching for git log, or any other output, it has to be git diff output, because then I am parsing it with the parser I made.

For now I have:

All unstaged files:

git diff

Staged + unstaged files + all local commits (compare to remote)

git diff origin/master

Now I am missing the part when I can get git diff for all unstaged and staged files, but not compare it with remote (cuz it would take all local commits too), but just compare it with last local commit. Is there a way to do this?

dabljues
  • 1,663
  • 3
  • 14
  • 30
  • Doesn't quite fit your requirements, but [`git diff --cached`](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgt--cachedltcommitgt--ltpathgt82308203) will show you just the staged files - perhaps that combined with `git diff` will be enough to achieve your goal? – DaveyDaveDave Aug 09 '19 at 10:27
  • 2
    Not quite a duplicate question, but [this answer](https://stackoverflow.com/questions/9903541/finding-diff-between-current-and-last-version/9903570#9903570) might be helpful - it's suggesting `git diff HEAD` will show what you're looking for – DaveyDaveDave Aug 09 '19 at 10:30
  • You might actually need *two* `git diff`s. Try this as an experiment in a temporary clone: take some file, such as `README.md`, and modify it and `git add README.md`. Now modify it *again*. Run `git status`. How many times does `README.md` show up? How will one `git diff` ever tell you that you have two *different* changes to the one file named `README.md`? – torek Aug 09 '19 at 17:24

1 Answers1

6

Taken from this answer, to a similar (but I don't think duplicate) question, I think what you're looking for is:

git diff HEAD

This will show you all the differences between your current working directory (i.e. your staged and unstaged changes) and the HEAD commit.

Or - if you prefer to match the syntax in your question, this would do the same thing:

git diff master

(where master is your current branch).

DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77