0

How do I git pull something on a previous commit on a repository? I'm following a guide in which half of the code was outdated and the other half is not. So I need to send that one half back to its previous state on my local files. Or should I be using checkout? I found the commit I think I need but I cannot get it to replace my files. Thanks in advance.

apollokedar
  • 17
  • 1
  • 5
  • Have you seen this [SO post](http://stackoverflow.com/questions/2007662/rollback-to-an-old-commit-using-git)? – David Tansey Apr 30 '14 at 02:24
  • Yes, I want to do the equivalent of a git pull I think. It is not my respository and I don't intend on ever pushing my changes. – apollokedar Apr 30 '14 at 14:08

2 Answers2

1

Use git log to find the SHA of the commit you want to roll back to, then:

git checkout <SHA of commit>

To change the contents of the commit, just type

git rm [-options] <Path to file (or directory)>

Then

git commit --amend
git push origin master //Optional

to complete your changes.

0

To restore some files to a previous state -say to commit with sha1 abc-, you could do

git checkout abc -- file1 file2 dir1
git commit -am "Rolled back some files"

Doing so will add a new commit on your current branch, with those files in their old state.

gturri
  • 13,807
  • 9
  • 40
  • 57