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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do the following:
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.txtwas like in the grand-parent of commitf414f31you can do: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 diffmeans “what changes haven’t I staged yet?”git diff --cachedmeans “what changes have I already staged?”