I had a problem with fetch and rebase.
I have a branch named oybek
. Then, I typed commands: git fetch
, git rebase origin/main
.
Then all my code was changed. How do I return to my previous code?
I had a problem with fetch and rebase.
I have a branch named oybek
. Then, I typed commands: git fetch
, git rebase origin/main
.
Then all my code was changed. How do I return to my previous code?
Firstly, commit/stash every changes first in case you mess things up. Once things are committed you can recovery them more easily if you go wrong.
You can see the commits you visited in git reflog
. Search for rebase (start)
pattern, the commit below that commit is the one you want. Copy its hash.
Let's say the hash is xxxxxxxxx
. You can now git checkout -b my-previous-place xxxxxxxxx
. Then there will be two branch, one before rebase and one after rebase.
This workflow is very safe because you lose nothing compare to using git reset
.