Kapil Gupta
Kapil Gupta

Reputation: 7721

How to view the previous commits of a repo?

I am reading an open source library with >1000 commits. I want to read the repository at different commits. I dont want to reset anything either locally or remotely. What are the commands that are needed for that?

Upvotes: 1

Views: 819

Answers (3)

Sajib Khan
Sajib Khan

Reputation: 24194

$ git log                     # see the commits and copy hash you want to go
$ git checkout <commit-hash>  # checkout to that commit

$ git checkout <branch-name>  # back to the HEAD of branch  

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522571

I want to read the repository at different commits.

The easiest and cleanest way to do this is to use a diff tool in your IDE (e.g. IntelliJ, Eclipse) or Git tool (e.g. SourceTree). This will allow you to compare any two commits in a branch.

If you really need to do some serious poking around at previous commits, then I would recommend that you checkout the branch at a previous commit via:

git checkout <sha1>

where <sha1> is the hash of the commit you want to inspect. When you are finished looking around, to return to the regular branch just use:

git checkout yourBranch

Upvotes: 2

tdao
tdao

Reputation: 17713

If you just want to review previous commits, then git log --oneline would probably all what you need.

If you then want to revert to a particular commit, say A, then

git checkout -f A -- .

Upvotes: 1

Related Questions