Git: How to see the old version of a file (before it was added to the staging area / index)?

Suppose I foo.txt my foo.txt file and run git add foo.txt . Now foo.txt appears in the list of "changes to be made."

Now I would like to see my foo.txt before these changes. How to do it with git ?

+7
source share
2 answers

You can do the following:

 git show HEAD:foo.txt 

In general, this syntax is very useful for viewing a file from a specific commit without touching your working tree. For example, if you want to see what was README.txt in grand-parent commit f414f31 , you can do:

 git show f414f31^^:README.txt 

Update: like VonC below, it is important to note here that the path here should be the full path from the root of the working tree, even if you are currently in a subdirectory.

However, when changes in the development stage are usually most often interested in differences, which means Abisern interpreted your question as a question . Simple thinking about these commands:

  • git diff means "what changes have not been made yet?"
  • git diff --cached means "what changes have I already made?"
+12
source

I think you are asking about differences (which show differences between file versions)

I wrote about them here

But the summary chart:

enter image description here

+6
source

All Articles