Aleks Ya
Aleks Ya

Reputation: 909

Show file content from index

I added a file to the index. And edit this file in working tree. There is two different versions of the file. I want to see version from index.

How to do it easiest?

==============
Duplicates:
How can I get content of a file from git index?
Git: Show content of file as it will look like after committing

Upvotes: 1

Views: 1007

Answers (3)

CodeWizard
CodeWizard

Reputation: 142632

As you mentioned - once you adding file to the index you can continue and modify it while the indexed version remains unchanged.

In order to view the index content you have to use

git show :<file>

The : are mandatory and you must have them in your cli command

Upvotes: 0

CB Bailey
CB Bailey

Reputation: 793109

git show :file

shows the version of file in the index. It prints it out or pipes it to your configured pager.

Alternatively, you can check out the index version to a temporary subdirectory with something like:

git checkout-index --prefix=tmp/ file

Upvotes: 3

Alex Wolf
Alex Wolf

Reputation: 20158

Use git diff --cached <path to file>.
This will show you the differences which are on the index.

Take a look at the documentation.

Upvotes: 0

Related Questions