7

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?

mbx
  • 6,292
  • 6
  • 58
  • 91
Michael
  • 10,185
  • 12
  • 59
  • 110

2 Answers2

12

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?"
Community
  • 1
  • 1
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • +1, but as mentioned in http://stackoverflow.com/questions/2108405/branch-descriptions-in-git/2108832#2108832, and illustrated here http://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch/2364223#2364223, you need to use the full path form the root directory of the repo when using `git show`. – VonC Sep 18 '11 at 14:54
  • Thanks, VonC - I've updated my answer to include that useful reminder. – Mark Longair Sep 18 '11 at 15:08
6

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:

enter image description here

Abizern
  • 146,289
  • 39
  • 203
  • 257