22657

How do I rollback to a specific git commit

I have rolled back already using this command git reset --hard HEAD^ to some previous commit, all I want to do is rollforward I know this isn't the correct term to what would be my commit that I did latest. Whats happening is a bunch of files were deleted when I used that command and now I don't know how to get back. I am using github is there a way to just pull down from github and overwrite the current directory?

Answer1:

Looking at your question, the commit you want to retrieve is the current one on the master branch of the GitHub repo, you have to do the following

git reset --hard origin/master

WARNING this will erase all uncommitted modifications that you could have made since you rolled back on HEAD^.

Before, you might want to do

git fetch origin

To make sure you've got the latest changes from the GitHub repo.

Answer2:

Take a look at git reflog. Among its output you should find the commit you want to reset to. Then git reset --hard to it and you're back where you were before your first reset.

git reflog is especially useful if you really screw your local repository up and don't have a remote repository you can use to pull commits from. It should work fine as long as you haven't called git prune to get rid of old commits or git reflog expire to clean the reflog.

Recommend

  • C# “cannot assign field because it is a foreach iteration variable”
  • How to get to older Xcode beta version?
  • HABTM associations in Rails : collecting and counting the categories of a model's children
  • CSS: How to fix overlapping divs
  • Problem in concatenation of objects in javascript
  • SSIS Designer is running VERY slowly
  • C Program Compiled with Cygwin and Called from Python Hangs
  • 'doc_del_count' bigger than 'doc_count' on CouchDB
  • Why can't I use non-integral types with switch [duplicate]
  • How do you create a Fuseki SPARQL server using the Apache Jena Java API?
  • Double dispatch in Java example
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • Mixing WebForms and MVC: What should I do with the MasterPage?
  • How can I get the choice “H2” back in the H2 consol?
  • Upload file that is in the cpan database
  • How to get links to open in the native browser in iOS Meteor apps?
  • jQuery: add elements until a particular height is reached
  • Application level floating views with navigation in Android
  • Who propagate bugfixes across branches (corporate development)?
  • Looking for good analogy/examples for monitor verses semaphore
  • Login not working in Firefox in Meteor
  • How to generate and display a QR Code in ionic 2
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Unable to get column index with table.getColumn method using custom table Model
  • How to use carriage return with multiple line?
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Ajax Loaded meta Tags
  • How to rebase a series of branches?
  • Jenkins: How To Build multiple projects from a TFS repository?
  • Can I display google adwords (AdView) in javafx on android
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • TFS: Get latest causes slow project reloading
  • Controls, properties, events and timers running in design time
  • Shallow update not allowed (git > 1.9)
  • Can I make an Android app that runs a web view in Chrome 39?
  • SVN: Merging two branches together
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Is there a mandatory requirement to switch app.yaml?
  • Revoking OAuth Access Token Results in 404 Not Found
  • Busy indicator not showing up in wpf window [duplicate]