E.E.33
E.E.33

Reputation: 2011

Is it possible to view and use older versions of a file by only accessing my local repository?

Lets say, I don't have access to github. How is my local repository useful to me? Can I roll back files to early versions? If so, how is it done?

Upvotes: 0

Views: 195

Answers (2)

Jeff Burdges
Jeff Burdges

Reputation: 4261

Your local repository has the entire project history for whatever branches it contains. Please note it might not contain all branches listed on github.

You should read the git-checkout man page, which explains how one accesses various versions, and the git-show man page, which differs slightly in syntax. You should probably also read the reset section in the Git Book as well .

In short, git checkout <revision> <file> replaces the current working with the one form <revision> and git show <revision>:<file> just shows it. HEAD names the last committed revision, HEAD^ the preceding one. git log lists them all, most recent first with commit messages.

Check out git-bisect if you want to see something really cool. :)

Upvotes: 0

opqdonut
opqdonut

Reputation: 5159

Your local repository contains a full history. This is easily seen by launching gitk, a graphical explorer of your git history.

To get older versions of files, you can use for example git checkout <revision> <file>. For example git checkout HEAD^ foo.txt will give you the foo.txt from the previous revision.

Another way of exploring old versions of files is git show <revision>:<path> which will show you the old contents of the file in a pager instead of checking it out into your working tree.

The only commands that access other repositories (github in this case) are git push, git pull and git fetch. All other git operations work solely on locally available information.

Upvotes: 1

Related Questions