How to explicitly refer to the current uncommited state of a repo in a git diff

git stash
git status
git diff between commits
git log
git diff specific file
git commit
git reset
git add

When you run git diff or git diff <some commit> you're implicitly diffing the current state of the repo (whether staged or unstaged) implicitly against HEAD implicitly in the first case or whatever commit is specified in the latter case.

My question is: how do I explicitly refer to the current state of the repo? Ideally, I'd like to be calling something like git diff CURRENT_STATE HEAD.

how do I explicitly refer to the current state of the [work tree]?

git diff is already an explicit reference to that, Git compares against the current state of the work tree unless you override it and tell it to compare against content somewhere else instead, but if you're after a further override like --no-cached to override any earlier --cached override, that, git diff doesn't have at the moment, you'll have to write a little options preprocessor to strip out anything you don't like rather than just tacking the override on the end.


Ideally, I'd like to be calling something like git diff CURRENT_STATE HEAD

You can get this effect with -R, a reverse diff that swaps the usual order. You'd do that specific diff with just git diff -R HEAD (I much prefer the @ synonym for HEAD, git diff -R @).

Recording Changes to the Repository, If the file didn't exist before, and you run git status , you see your untracked file like so: nothing added to commit but untracked files present (use "git add" to track) Git won't start including it in your commit snapshots until you explicitly tell it to do so. If you've staged all of your changes, git diff will give you no output. git diff --cached: Print out differences between the index and HEAD (current commit). git diff HEAD: Print out differences between your working directory and the HEAD. git diff --name-only Show only names of changed files. git diff --name-status Show only names and status of changed files. git diff --color-words Word by word diff instead of

jthill's answer is fine; I just want to address this comment directly, with much more detail and formatting than will fit into a comment:

Basically, I'm asking: Does the uncommitted state of the repo explicitly have its own ref?

The short answer is "no".

A ref, like HEAD or master or (fully spelled out) refs/heads/master, ultimately resolves to a hash ID.1 If it's a branch name or remote-tracking name, it resolves specifically to a commit hash ID; if it's a tag name, it may resolve to any of Git's four internal object types: commit, tree, blob, or (annotated) tag.

A tree object is the closest thing you can get to the work-tree, but it's not the work-tree at all. In fact, there are two uncommitted representations, in a normal Git repository, that you cannot refer to by name. One of these is the stuff that is in the index—essentially, the proposed next commit—and the other is the stuff in the work-tree.

If the index is in a good state,2 you can run git write-tree. The result is a hash ID. This is not a reference name at all, it's just a hash ID, but a hash ID is usually just as good. So if you'd like some Git command to take notice of the proposed next commit, you can run git write-tree to write it to a tree object, and then use the resulting hash ID.

The work-tree, however, isn't at all suitable for this. To turn the work-tree into a hash ID, you need to write it to the—or at least an—index and then run git write-tree. You can use the environment variable GIT_INDEX_FILE to name a temporary file that will hold a temporary index.

The git diff and git status commands have built-in tricks to use the index and work-tree as if they were commits, but most other Git commands don't.

1If the ref is symbolic—as HEAD usually is—it just contains the name of another ref. If that other ref doesn't actually exist, the symbolic ref won't resolve to a hash ID at all, and git rev-parse will fail on it, but git symbolic-ref will let you examine the target.

2The index can be in the merge conflict state, in which it can't be converted into a tree object. In this case git write-tree just errors out. Unfortunately, there is no good way to deal with this other than just to resolve the merge conflicts. I say "unfortunately" because it would sometimes be very handy to stash (as if by git stash or some such) the conflicted state for safekeeping and/or transport, and the way Git is today, that's simply not possible. You can get pretty close, using git ls-files --stage to translate the index into text and git update-index to invert that, but protecting temporary blob hashes from GC is a problem.

git-status Documentation, Displays paths that have differences between the index file and the current the textual changes that are staged to be committed (i.e., like the output of git diff --​cached ). When matching mode is specified, paths that explicitly match an ignored The command honors color.status (or status.color — they mean the same  These data sources can be commits, branches, files and more. This document will discuss common invocations of git diff and diffing work flow patterns. The git diff command is often used along with git status and git log to analyze the current state of a Git repo. Reading diffs: outputs Raw output format

you can specify two commits to git diff:

git diff [--options] <commit> <commit> [--] [<path>...]
   This is to view the changes between two arbitrary <commit>.

Please write:

git help diff

For more options.

Good luck!

git-diff Documentation, git-diff - Show changes between commits, commit and working tree, etc See the description of the --diff-filter option on what the status letters mean. Giving it explicitly overrides any diff driver or configuration setting. tip of "test" branch, compare with the tip of the current branch, but limit the comparison to the file "test​". The git reset command also includes options to update the other parts of your local environment with the contents of the commit where you end up.These options include: hard to reset the commit being pointed to in the repository, populate the working directory with the contents of the commit, and reset the staging area; soft to only reset the pointer in the repository; and mixed (the default

Git Diff, Saving changes in a repo: git add adds a change in the working directory to the The git diff command is often used along with git status and git log to analyze the In our current example, we only have one chunk as we are working with a simple scenario. The git diff command can be passed an explicit file path option. git diff. Let’s stop for a minute to see how the git diff command can be used to show you the difference between the version of a file in the working directory, index and most recent commit. The 3 main types of git diff commands you would likely use are: git diff: Show differences between your working directory and the index.

10 insanely useful Git commands for common Git tasks, 10 most useful git commands guide: the intuitive and actual commands for common and dirs in your own local copy of a repository, and you want to delete those files, Git tip: When a file is removed from Git, it doesn't mean it is removed from history. Find the diff between the tips of the two branches: $ git diff branch_1.. We should use the git diff command to check for differences. But if we run git diff now we won’t see any output. [sahil@linuxnix my_first_repo]$ git diff [sahil@linuxnix my_first_repo]$ This is because since the file is now in the staging area, git knows about the file and so it doesn’t see a difference.

API Reference, Update the submodules of this repository to the current HEAD commit. Progress messages will change accordingly to indicate the WOULD DO state of the operation. the -1 * ( that was made explicit here ) :param utctz: git utc timezone string, i.e. +0200 Diff this index against the working copy or a Tree or Commit object. git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on.. Stashing is handy if you need to quickly switch context and work on something else, but you're mid-way through a code change and aren't quite ready to

  • git diff HEAD is (contrarily to the behaviour of most git commands) different than git diff. I'm unsure about what you precisely want, but could it suit your needs?
  • what does current state of the repo mean, the remote repo? You are referring to the current state of your repo
  • By current state of the repo, I meant more current state of the local files. Basically, I'm asking: Does the uncommitted state of the repo explicitly have its own ref?