Git Checkout returned code for an older commit, how to go back?

I worked on some code that I use git for control. I used to use commit to save the version of my code that worked. Later, I decided to redo the code, because it needed some new features, and it was poorly designed. After I got it, I made another git commit. After running git magazine, I saw that I was not in any industry. So, I made a "git validation wizard." This reverted to the version of my old code, with git log now showing my last commit. It was a lot of work, so I wanted to know if there was a way to undo what I did and return my last code. Thanks in advance for your help.

+5
source share
2 answers

Check git reflogand find your commit.

The safest thing is to create a branch in the β€œlost” commit, and then check to see if everything is dandy using gitkorgit log -p

git branch recovery HEAD@{1} # use whatever commit you need
git log -p recovery

This new branch can then be merged, recreated on top of the master, waving it, etc. There are many possibilities in git to shoot yourself in the leg, as well as several other ways to re-attach this leg (possibly to the arms).

If you have not made any new commits to master, you can simply merge the commit in question, which will be resolved as a quick merge with git:

git merge HEAD@{1} # use whatever commit you need

- master, , reset , git reset. - , (git stash save)

git reset --keep HEAD@{1}

, , - , git branch newbranch git checkout -b newbranch

+12

git reflog, ( , HEAD@{1}), git cherry-pick, git merge .., master.

+1

All Articles