The git-diff manual pages says that git diff is used to
Show changes between the working tree and the index or a tree, changes between the index and a tree, changes between two trees, or changes between two files on disk.
But what about if you want to show the difference between a commit prior to HEAD and the working directory? Is that possible?
The git diff command shows the differences between the files in two commits or between your current repository and a previous commit.
You can access the commit history with the Git log. The working tree, or working directory, consists of files that you are currently working on. You can think of a working tree as a file system where you can view and modify files. The index, or staging area, is where commits are prepared.
git commit -- takes the commit message from the given file. In the parameter you should enter the name of the file you want from your repository. git commit --only is the default mode of operation of git commit.
The git diff command is used when you want to see differences between any two trees.
Yes, but it depends a bit on your definition on what the “current project state” is. The manual for git diff goes on.
If you are interested in comparing with the staged changes:
git diff [--options] --cached [<commit>] [--] [<path>...]
This form is to view the changes you staged for the next commit relative to the named
<commit>
. Typically you would want comparison with the latest commit, so if you do not give<commit>
, it defaults to HEAD. If HEAD does not exist (e.g. unborned branches) and<commit>
is not given, it shows all staged changes.--staged
is a synonym of--cached
.
If you are interested in comparing with the unstaged changes:
git diff [--options] <commit> [--] [<path>...]
This form is to view the changes you have in your working tree relative to the named
<commit>
. You can use HEAD to compare it with the latest commit, or a branch name to compare with the tip of a different branch.
Or if you are just interested in comparing any two commits (one could be HEAD):
git diff [--options] <commit> <commit> [--] [<path>...]
This is to view the changes between two arbitrary
<commit>
s.
So you might want to run git diff someOldCommit HEAD
to see the differences between someOldCommit
and the current HEAD.
It ist just simple:
git diff HEAD
Explanation: Current changes in the working directory compared with the last commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With