About this question
In Git, how do undo git rebase if not happy with it?
Git doesn't have dry-run for rebasing. If I did a rebase and have not pushed it yet, how do I rollback to before, as if it never happened?
In Git, how do undo git rebase if not happy with it?
Git doesn't have dry-run for rebasing. If I did a rebase and have not pushed it yet, how do I rollback to before, as if it never happened?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Salesforce Expert
Answered on Nov 17, 2022
Suppose you did a git rebase in your local branch but mistakenly rebased to an older branch and pushed changes to remote, then here is the solution to undo rebase and go back to the previous state. Back up all your changes. Use git reflog to see all your previous operations. git log will show rebased and squashed changes only. Find out the commit where you want to go back to. Most probably this will be the commit before your rebase operation. You will see commit ids like HEAD@{16} Now reset your local branch to this commit.
git reset --hard HEAD@{16}
This only moves the local branch to HEAD@{16}
Now check the status of your local branch.
git status
On branch my_branch Your branch and 'origin/my_branch' have diverged
Now this is frustrating.
This means your local branch and remote branch have diverged as your local branch has gone back to a previous commit while remote branch is still ahead.
Force your remote branch to go back to where your local branch is.
git push --force
NOTE: At any stage, if you think you have made a mistake and want to reset your local branch with the current remote branch HEAD,
git reset --hard origin/HEADPerry Burt Latest answer
Answered on Jun 18, 2024
Thanks Pawar for sharing in great detail how to undo git rebase. geometry dash
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Salesforce guides from industry experts
Common Salesforce interview questions, answered
Guides, tips and career advice on Salesforce from JanBask experts.
Salesforce How to Become a Salesforce Developer Without Experience
No coding background? Learn how to become a Salesforce Developer step by step - skills to build, projects to create, and how to…
Salesforce How to Become a Salesforce Admin With No Experience
No Salesforce Admin experience? Learn how to build real skills, create projects, and land an entry-level Salesforce Admin job…
Salesforce How Long Does It Take to Become a Salesforce Developer?
Wondering how long to learn Salesforce Developer? Most beginners need 6–12 months. See the study time, stage-by-stage roadmap and…
Salesforce How Long Does It Take to Become a Salesforce Admin?
Wondering how long to learn Salesforce Admin? Most beginners need 3–6 months. See the study time, stage-by-stage roadmap and…