Return to previous commit

8

I work in a branch called master2 , the issue is that I made small changes in 1 file and when I tried to upload them, I made an error and I did git pull origin master and when doing push I found almost all the files in the repository with conflict, try to solve them but there was no case. I need to go back to the last stable version of the repository or if it is possible, revert the changes or delete the commits

EDITING

There are 4 commits after which I would like to return, could I get back 4 commits before?

    
asked by sioesi 29.12.2016 в 12:04
source

3 answers

9

You can go back to an old revision using checkout and passing the commit hash. For example:

git checkout ab25f1ln2b4o3a9c4u1v6k4n1m7 .

Do not forget the point at the end. You can also discard changes by reset by passing the number of commits. For example, to discard the last 3 commits:

git reset --hard HEAD~3

The difference between checkout and reset is that in the latter they discard the revisions, while with checkout they are preserved.

    
answered by 29.12.2016 / 12:34
source
3

In your case you probably do not want to keep the changes then:

git reset --hard HEAD~3

Or simply use the commit id:

git checkout <id commit>

If you want to keep the changes and return 4 commits before:

git reset [--mixed] HEAD~3

If you only want to move the head to 4 changes before:

git reset --soft HEAD~3
    
answered by 29.12.2016 в 13:01
1

You can go back to the last commit of the branch with git reset --hard (check that you are in the correct branch with git status ).

You can also see your previous commits with git log and choose one of those commits with git checkout codigo_del_commit .

Unfortunately you will have to find a stable version of your project through old commits, (git uses commits as save points).

If you do not save the game and you're killed, you'll be back at the last point where you saved

    
answered by 29.12.2016 в 12:28