FreeKB - Viewing the content of a file in Git
Viewing the content of a file in Git

Home > Search


If you are not familiar with Git, check out our getting started article. These examples are based on Linux. Let's say you've added and commited example.txt in Git, and example.txt contains the following.

Foo

 

Then you replaced Foo with Bar, and commited example.txt.

Bar

 

The git log will show both commits.

afba75a second commit
741785c first commit

 

The git show command can be used to view the content of the file at a specific commit. The syntax of git show is:

git show <commit id>:<path to file>

 

The git show command can be used to determine the appropriate path to the file.

git show <commit id> --name-only

 

Which will return a result such as:

misc/example.com

 

In this example, the state of the file in first commit will be displayed.

git show 741785c:misc/example.txt

 

Which will have Foo, in this example.

Foo

 

In this example, the state of the file in second commit will be displayed.

git show afba75a:misc/example.txt

 

Which will have Bar, in this example.

Bar

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter ab918 in the box below so that we can be sure you are a human.




Comments