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
?
git checkout recovers old versions of files.
Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With