Naoto Ishida
Naoto Ishida

Reputation: 31

Is there a way to show file in working tree by Git?

I know git show HEAD:<file> shows file content of HEAD revision, and git show :<file> shows file content of INDEX, but I can't show file content of working tree using git.

Like less <file>, it can be achieved very easy by other commands, but I want to do this only using git commands.

Upvotes: 1

Views: 189

Answers (1)

torek
torek

Reputation: 488183

Not directly, no. Most Git commands operate on what is in the repository itself, and the version in the work tree is not in the repository.

You could, of course, git add the work-tree version so that it is now in the repository via the index, but that would—at least potentially—overwrite a version that exists only as an index entry, e.g., from git add -p. (This actually leaves an unreferenced blob in the repository proper, so if you have the hash and the blob has not been garbage-collected, you can still retrieve that file, but this is well into "crazy" territory. :-) )

Upvotes: 1

Related Questions