DMCoding
DMCoding

Reputation: 1237

Git: Journeying to the beginning of time and back again

As a relative newcomer to git, there is something that I have never quite managed to work out -- how to easily rewind and fast-forward to different points in a branch's timeline.

Today, I need to write a report which involves making screenshots from the codebase at the beginning of the git revision history and comparing it to how the program looks now. What's the easiest way to do this in git?

Upvotes: 3

Views: 114

Answers (3)

Tim
Tim

Reputation: 43314

..how to easily rewind and fast-forward to different points in a branch's timeline.

Today, I need to write a report which involves making screenshots from the codebase at the beginning of the git revision history and comparing it to how the program looks now. What's the easiest way to do this in git?

Going back in time with git is surprisingly easy. Suppose your history looks like this

hash  : commit message
======================
3q4htq: fixed bug that the new feature introduced
364572: added a new feature
44tdrt: made some more stuff
235326: made some stuff for the first time
224y4y: Initial commit

(commit hashes are made up)

Say you want to go back to the state the project was in at the time commit 235326 was made. All you need to do is

$ git checkout 235326

You can now view files and make your screenshots of the code. When you are ready to go back to "the future" you can simply do

$ git checkout master

or replace master with whatever branch name or commit hash you originally came from. You can use checkout command like this to 'jump around' in the project history.

Upvotes: 1

Jonathan.Brink
Jonathan.Brink

Reputation: 25393

If your report involves a presentation I would highly recommend running "gource" on your code-base (impressive eye candy!).

This tool let's you truly visualize how your graph of commits evolved over time.

Check out the "History of Python" gource representation.

Upvotes: 2

npe
npe

Reputation: 15709

From what I understand, you want to create a patch that turns some initial commit, into the final commit.

Let's say you have a git log output like this:

* 58ef3f6 [maven-release-plugin] prepare for next development iteration
* 15ded94 [maven-release-plugin] prepare release 1.7
* 1687ba4 fix some more bugs
* 1687ba4 fix some bugs
* a4f3918 implement new feature
* c2065d1 update datasources
* 06349b5 set up external interfaces
* 723e37f branched from trunk

Then, to create a cumulative patch of the changes between 723e37f and 58ef3f6 you'd do:

git diff 58ef3f6 723e37f 

On the other hand, if you want to see how the code looked like at a specific point in time, you just need to checkout specific commits, e.g.:

git checkout 58ef3f6 

Upvotes: 2

Related Questions