Using git diff, how can I show the patch from the index to a given commit?

cmaster - reinstate monica

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
torek

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I prevent 'git diff' from using a pager?

From Dev

In Git how can I see the diff from master to develop?

From Dev

How can I fetch header info from git patch using python?

From Dev

git - how can I configure interactive commits to always show a diff?

From Dev

how to do a git diff of current commit with last commit using gitpython?

From Dev

How can I stop myself from using 'git commit -a'?

From Dev

How can I display the committer using git diff

From Dev

How can I restore only a few lines from a file recorded in a given commit?

From Dev

How can I create a patch to delete a folder and create new folder using diff?

From Dev

In Pandas, how can I patch a dataframe with missing values with values from another dataframe given a similar index?

From Dev

How can I rebase as one commit using Git

From Dev

Can I get git fsck to show commit names?

From Dev

How can I limit the log to all the descendants of a given commit?

From Dev

How can I generate a diff patch file for only committed files?

From Dev

how to get git diff to only show commit messages

From Dev

How can I remove an applied git patch?

From Dev

How can I create a GIT Stash from a Commit?

From Dev

How can I revert back to a Git commit?

From Dev

How do I apply this revert commit patch from git?

From Dev

Can I get a .patch file from a svn commit without svn?

From Dev

How to make git not show the deleted file list after I commit

From Dev

Git show <commit> and get diff for a file subset

From Dev

how to get git diff to only show commit messages

From Dev

How can I create a GIT Stash from a Commit?

From Dev

Git - How do I show file content for each file in the commit?

From Dev

How can I find added lines (not changed) using git diff?

From Dev

How to select the appropriate diff /patch for a commit with rugged

From Dev

Git: reset to a too old commit, and git log , only show from the commit I have now

From Dev

How can I extract Git commit hash from VS/msbuild?

Related Related

  1. 1

    How do I prevent 'git diff' from using a pager?

  2. 2

    In Git how can I see the diff from master to develop?

  3. 3

    How can I fetch header info from git patch using python?

  4. 4

    git - how can I configure interactive commits to always show a diff?

  5. 5

    how to do a git diff of current commit with last commit using gitpython?

  6. 6

    How can I stop myself from using 'git commit -a'?

  7. 7

    How can I display the committer using git diff

  8. 8

    How can I restore only a few lines from a file recorded in a given commit?

  9. 9

    How can I create a patch to delete a folder and create new folder using diff?

  10. 10

    In Pandas, how can I patch a dataframe with missing values with values from another dataframe given a similar index?

  11. 11

    How can I rebase as one commit using Git

  12. 12

    Can I get git fsck to show commit names?

  13. 13

    How can I limit the log to all the descendants of a given commit?

  14. 14

    How can I generate a diff patch file for only committed files?

  15. 15

    how to get git diff to only show commit messages

  16. 16

    How can I remove an applied git patch?

  17. 17

    How can I create a GIT Stash from a Commit?

  18. 18

    How can I revert back to a Git commit?

  19. 19

    How do I apply this revert commit patch from git?

  20. 20

    Can I get a .patch file from a svn commit without svn?

  21. 21

    How to make git not show the deleted file list after I commit

  22. 22

    Git show <commit> and get diff for a file subset

  23. 23

    how to get git diff to only show commit messages

  24. 24

    How can I create a GIT Stash from a Commit?

  25. 25

    Git - How do I show file content for each file in the commit?

  26. 26

    How can I find added lines (not changed) using git diff?

  27. 27

    How to select the appropriate diff /patch for a commit with rugged

  28. 28

    Git: reset to a too old commit, and git log , only show from the commit I have now

  29. 29

    How can I extract Git commit hash from VS/msbuild?

HotTag

Archive