Suppose I changed my file foo.txt
and run git add foo.txt
. Now foo开发者_如何学编程.txt
appears in the list of the "changes to be committed".
Now I would like to see my foo.txt
before these changes. How can I do it with git
?
You can do the following:
git show HEAD:foo.txt
In general, this syntax is very useful for seeing a file from a particular commit without touching your working tree. For example, if you want to see what README.txt
was like in the grand-parent of commit f414f31
you can do:
git show f414f31^^:README.txt
Update: as VonC comments below, it's important to note here that the path here must be the full path from the root of the working tree, even if you're currently in a subdirectory.
However, when staging changes, one does tend to be more often interested in differences, which is what Abizern interpreted your question as asking about. A simple way of thinking about those commands is:
git diff
means "what changes haven't I staged yet?"git diff --cached
means "what changes have I already staged?"
I think what you're asking is about diffs (which show the differences between versions of files)
I've written about them here
But a summary diagram is:
精彩评论