I am fully aware that
git diff --cached <commit>
will show me the patch from <commit>
to my current index. However, I want to get the patch the other way round, from the index to the given <commit>
. Is this possible? And if yes, how?
Corollary: How can I get the diff from the current working directory to a <commit>
, or to the index?
I guess, what I would want to have is some kind of syntax that lets me specify the index or working directory within a commit range like this:
git diff <index>..<commit> #opposite of git diff --cached <commit>
git diff <workingDir>..<commit> #opposite of git diff <commit>
git diff <workingDir>..<index> #opposite of git diff
You are right that you need a bit of syntax, although rather than being able to name the index or work-tree, in this case the syntax to use is the -R
(reverse diff) option:
diff -R --cached <commit>
and so on. (This is not needed when comparing two commits since you can swap them on the command line, but is needed for the cases you noted, and it also works for this last case.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments