tags:

views:

2871

answers:

3

I cloned a git repository and then tried to roll it back to a particular changeset early on in the development process. Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent changes from my local source code.

However, when I try to roll back in the GUI tool it doesn't update my local file system - I always end up with the latest source code for the project.

What's the correct way to just get the source for a repository as of a particular commit in the project's history and omit all later updates?

+12  A: 

git reset --hard <tag/branch/commit id>

kauppi
git reset without the --hard option resets the commit history but not the files. With the --hard option also files in working tree are reset.
kauppi
Just what I needed. Thank you!
+8  A: 

A slightly less scary way to do this than the git reset --hard method is to create a new branch. Let's assume that you're on the master branch and the commit you want to go back to is c2e7af2b51.

Rename your current master branch:

git branch -m crazyexperiment

Check out your good commit:

git checkout c2e7af2b51

Make your new master branch here:

git checkout -b master

Now you still have your crazy experiment around if you want to look at it later, but your master branch is back at your last known good point, ready to be added to. If you really want to throw away your experiment, you can use:

git branch -D crazyexperiment
Neall
Thanks - might not have been what the poster asked for, but much less anxiety-inducing for me.
Matt Parker
A: 

From the root directory of your working copy

git checkout c2e7af2 -- .

totoro