Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I view an old version of a file with Git?

Is there a command in Git to see (either dumped to stdout, or in $PAGER or $EDITOR) a particular version of a particular file?

like image 900
mike Avatar asked Dec 03 '08 19:12

mike


People also ask

Does git save old versions?

To be efficient, if files have not changed, Git doesn't store the file again—just a link to the previous identical file it has already stored. This is an important distinction between Git and nearly all other VCSs.

How do you check the history of a file in git?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

How do I restore an old version of a file GitHub?

Reverting To An Old Version of the Repository Start by navigating to the “History” tab. Right-click on the previous commit, and you'll see the option to revert this commit. If you click on Revert This Commit , two things will happen. The first is that the files in your repository will revert to their previous state.

How do I see previous commit files?

2.1 git log to display all the commit_id, the first one is the last commit_id, copy it. 2.2 git show commit_id --name-only to display all the files committed in the specified commit_id. 2.3 Undo the last commit with git reset --soft HEAD~1 , move the mistakenly committed files back to the staging area.


1 Answers

You can use git show with a path from the root of the repository (./ or ../ for relative pathing):

$ git show REVISION:path/to/file 

Replace REVISION with your actual revision (could be a Git commit SHA, a tag name, a branch name, a relative commit name, or any other way of identifying a commit in Git)

For example, to view the version of file <repository-root>/src/main.c from 4 commits ago, use:

$ git show HEAD~4:src/main.c 

Git for Windows requires forward slashes even in paths relative to the current directory. For more information, check out the man page for git-show.

like image 91
mipadi Avatar answered Sep 23 '22 07:09

mipadi