Back repository to the previous state [duplicate]

3

I have a project that we use GIT for versioning. However, one of the programmers uploaded a wrong version to the remote server, gave commit , push and several commits and pushs .

There the site got an error. We try git checkout <commit numero> , git revert and nothing!

I want to undo all the changes that he made on a certain date to what it was before, and figure out how to undo those changes after a user gives a push on the server.

    
asked by anonymous 03.09.2015 / 16:32

1 answer

4

First, give git log to retrieve the hash of all the last commits. For example:

git log -n 20 # lista os últimos 20 commits

In this listing, copy the hash of the last stable commit. Then give git rebase to rewrite commit history:

git rebase -i <hash do último commit estável>

(note: this command literally rewrites commit history, so be careful!)

Then you will enter a screen which lists all commits between the HEAD and the hash you have chosen. Discard the wrong commits by simply deleting the line for commits.

Finally, just give git push -f to upload the history rewrite to the remote repository.

On the server, just give git pull --rebase to search for the latest changes to the repository.

    
03.09.2015 / 16:42