{"id":17526,"date":"2022-04-19T12:15:33","date_gmt":"2022-04-19T17:15:33","guid":{"rendered":"https:\/\/alphaefficiency.com\/?p=17526"},"modified":"2022-04-19T12:15:33","modified_gmt":"2022-04-19T17:15:33","slug":"git-undo-rebase","status":"publish","type":"post","link":"https:\/\/alphaefficiency.com\/git-undo-rebase","title":{"rendered":"How to Undo Rebase in Git"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Rebase is a Git utility that serves for integrating changes from one branch to another. Along with <\/span><i><span style=\"font-weight: 400;\">git merge<\/span><\/i><span style=\"font-weight: 400;\">, it is the only change integration utility. While <\/span><i><span style=\"font-weight: 400;\">git merge<\/span><\/i><span style=\"font-weight: 400;\"> is a forward-moving process, <\/span><i><span style=\"font-weight: 400;\">rebase <\/span><\/i><span style=\"font-weight: 400;\">provides powerful history rewriting features. In a way, we can understand <\/span><i><span style=\"font-weight: 400;\">rebase <\/span><\/i><span style=\"font-weight: 400;\">as a merge with Git history.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">That being said, it may happen that you accidentally performed the <\/span><i><span style=\"font-weight: 400;\">git rebase<\/span><\/i><span style=\"font-weight: 400;\"> command on a local branch and pushed the changes to remote. So, which steps should you take to undo this action and resolve the problem? In today\u2019s article, our <\/span><a href=\"https:\/\/alphaefficiency.com\/code\"><span style=\"font-weight: 400;\">web development agency in Chicago<\/span><\/a><span style=\"font-weight: 400;\"> explores ways to undo rebase in Git. We\u2019ll also talk about common rebase use cases and caveats, as well as provide a detailed look at <\/span><i><span style=\"font-weight: 400;\">git rebase<\/span><\/i><span style=\"font-weight: 400;\"> configuration and execution.<\/span><\/p>\n<h2>What is rebasing in Git?<\/h2>\n<p><span style=\"font-weight: 400;\">Rebase is the process that allows you to move or combine a sequence of commits to a new base commit. In the context of a feature branching workflow, you can visualize the process, as shown in the figure below.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-17530\" src=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase1.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase1.png 800w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase1-300x225.png 300w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase1-768x576.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\n<p><span style=\"font-weight: 400;\">If we view this operation from a content perspective, we can say that rebasing is the action of changing the base of a branch from one commit to another. Developers use rebase to change the starting point of a branch in commit history to the final commit of the main or any other branch. In layman&#8217;s terms, rebase allows you to move the starting point of your branch to another point.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Though, at first glance, it may seem that your branch looks the same, it is essential to note that it is actually made of entirely new commits applied to the specific base.<\/span><\/p>\n<h3>Use cases<\/h3>\n<p><span style=\"font-weight: 400;\">Git rebase is most commonly used to maintain a linear history of your project. Let\u2019s say that the master branch of your project has further progressed while you were working on your feature branch. Now, you wish to get those master branch updates to your feature branch and keep your branch\u2019s history clean, so you can later seamlessly merge it back into the master branch. By doing rebase, you\u2019ll get the same outcome as if you were working off the latest master branch.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To better understand the benefits of keeping a clean branch history, imagine the following situation:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A bug appeared on the master branch that prevented a particular feature from functioning as intended. You use the <\/span><i><span style=\"font-weight: 400;\">git log<\/span><\/i><span style=\"font-weight: 400;\"> to check the history of the master branch. Since you and your team followed the practice of keeping a clean history, you\u2019ll have no problems understanding the data. If you cannot identify when the bug was introduced with the <\/span><i><span style=\"font-weight: 400;\">git log<\/span><\/i><span style=\"font-weight: 400;\"> command, you\u2019ll likely execute <\/span><i><span style=\"font-weight: 400;\">git bisect<\/span><\/i><span style=\"font-weight: 400;\">. Due to the clean history, <\/span><i><span style=\"font-weight: 400;\">git bisect<\/span><\/i><span style=\"font-weight: 400;\"> can work with a refined set of commits and compare them to find the one that introduced the bug, giving you the chance to act accordingly and promptly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are two ways to integrate your feature branch into the master branch:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Merging directly<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Rebasing, then merging<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">While the first option requires a three-way merge and a merge commit, the second option produces a fast-forward merge and a linear history like in the diagram below.<\/span><\/p>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-17531\" src=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png 800w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2-300x225.png 300w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2-768x576.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\n<p><span style=\"font-weight: 400;\">As you can see, rebasing allows you to integrate upstream changes into your local repo easily.<\/span><\/p>\n<p><b>Note<\/b><span style=\"font-weight: 400;\">: It is imperative to mention that you should never rebase commits that have already been pushed to a public repository. That action would replace the old commits with new commits, and it would appear that a part of your project history has disappeared.<\/span><\/p>\n<h3>Different git rebase modes<\/h3>\n<p><span style=\"font-weight: 400;\">There are two git rebase modes:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Standard<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Interactive<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Interactive git rebase is initiated using an <\/span><i><span style=\"font-weight: 400;\">&#8212; i <\/span><\/i><span style=\"font-weight: 400;\">argument that stands for <\/span><i><span style=\"font-weight: 400;\">interactive<\/span><\/i><span style=\"font-weight: 400;\">. Without this argument, the rebase process runs in standard mode. Let\u2019s use an example to differentiate these two modes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, let\u2019s say that we have created a separate feature branch and checked out.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git checkout -b feature_branch main<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After editing some files, let\u2019s commit changes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git commit -a -m \u201cAdds new feature\u201d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Standard rebase automatically applies your current working branch commits to the HEAD of the passed branch.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git rebase &lt;base&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This command-line rebases the current branch onto the commit reference of your choice. That could be an ID, a branch name, a tag, or a relative reference to HEAD.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By introducing the -i flag, you\u2019ll run an interactive rebasing process. Instead of moving all commits to the new base, this process allows you to clean up your history by removing, splitting, or altering existing commits.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git rebase &#8212; Interactive &lt;base&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You\u2019ll be presented with an editor, which you can use to enter various commands in order to determine how and in which order individual commits will be moved to the new base. Once you have all the actions specified, Git starts playing back commits and applying your commands. Here is a set of commands you cn use during an interactive rebase:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">p (pick) &#8211; use commit<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">r (reword) &#8211; use commit, but edit the commit message<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">e (edit) &#8211; use commit, but stop for amending<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">s (squash) &#8211; use commit, but meld into the previous commit<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">f (fixup) &#8211; similar to <\/span><i><span style=\"font-weight: 400;\">squash<\/span><\/i><span style=\"font-weight: 400;\">, but discard this commit log message<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">x (exec) &#8211; run command (the rest of the line) using shell<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">d (drop) &#8211; remove commit<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Besides the commands mentioned above, rebase provides additional commands for you to use in more complex situations. Here are some of those:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">git rebase &#8212; d &#8211; discards the commit from the final commit block during playback<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">git rebase &#8212; p &#8211; leaves the commit unchanged as an individual commit in the branches history<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">git rebase &#8212; x &#8211; executes a command shell script on each marked commit during playback (useful when running codebase\u2019s test suit on specific commits in order to identify regressions (bugs) during a rebase)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">With the help of interactive rebasing, you\u2019ll have full control over your project\u2019s history. Developers find this mode extremely useful since they can commit their history in the current state while they are preoccupied with coding and then go back and clean it up.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Interactive rebase allows you to polish your feature branch before merging it into the main codebase, which keeps the master branch history clean and meaningful.<\/span><\/p>\n<h2>How to undo git rebase?<\/h2>\n<p><span style=\"font-weight: 400;\">To undo git rebase, let\u2019s say we have master and feature branches, each with the following chain of commits (we\u2019ll mark commit messages with <\/span><i><span style=\"font-weight: 400;\">C <\/span><\/i><span style=\"font-weight: 400;\">to make things more simple and readable):<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Master: C4 &#8211; C2 &#8211; C1 &#8211; C0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Feature: C5 &#8211; C3 &#8211; C2 &#8211; C1 &#8211; C0<\/span><\/li>\n<\/ul>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-17532\" src=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase3.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase3.png 800w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase3-300x225.png 300w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase3-768x576.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\n<p><span style=\"font-weight: 400;\">If we use<\/span><i><span style=\"font-weight: 400;\"> git log<\/span><\/i><span style=\"font-weight: 400;\"> to look at the set of commits in each branch, it may look something like this:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git log &#8212; oneline master<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6a92e7a C4<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git log &#8212; oneline feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b8 C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">000f9ae C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">What Git does during rebase is take each commit in one branch and try to replay the differences onto the other branch. Now. Let&#8217;s attempt to rebase the feature branch onto the master branch by taking C4 from the master branch and placing it onto the feature branch. This is what it may look like:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git checkout feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git rebase master<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, rewinding head to replay your work on top of it\u2026<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Applying: C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Applying: C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Once this is done, your chain of commits should look like the following figure shows.<\/span><\/p>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-17533\" src=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase4.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase4.png 800w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase4-300x225.png 300w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase4-768x576.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\n<p><span style=\"font-weight: 400;\">Let\u2019s use <\/span><i><span style=\"font-weight: 400;\">git log<\/span><\/i><span style=\"font-weight: 400;\"> again to see if we can spot any changes:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git log &#8212; oneline master<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6a92e7a C4<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git log &#8212; oneline feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">c4533a5 C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">64f2047 C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6a92e7a C4<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As you can see, our new C3 and C5 commits differ from the previous ones. They are actually new commits created by making changes from the originals on top of the existing chain on the master branch. Let\u2019s name these new commits <\/span><i><span style=\"font-weight: 400;\">C3\u2019 <\/span><\/i><span style=\"font-weight: 400;\">and <\/span><i><span style=\"font-weight: 400;\">C5\u2019<\/span><\/i><span style=\"font-weight: 400;\">. The original C3 and C5 commits still exist, but they no longer have a branch pointing to them.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The rebase is finished, and now we decided to use <a href=\"https:\/\/git-scm.com\/\">Git<\/a> to undo rebase. We can do this by entering:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git reset 79768b8<\/span><\/p>\n<p><span style=\"font-weight: 400;\">With this command line, we have managed to undo rebase in Git, and our branch is once again pointing to the previous set of commits.<\/span><\/p>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-17534\" src=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase5.png\" alt=\"\" width=\"800\" height=\"600\" srcset=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase5.png 800w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase5-300x225.png 300w, https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase5-768x576.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\n<p><span style=\"font-weight: 400;\">Luckily, we were able to remember what commit the branch used to point to (C5), so it was easier for us to undo git rebase. But, what happens if we cannot recall the commit in question? Fortunately, Git remembers the original commit for most operations that modify pointers like rebase does. It is saved in the .git repository and named ORIG_HEAD. Let\u2019s use the <\/span><i><span style=\"font-weight: 400;\">cat <\/span><\/i><span style=\"font-weight: 400;\">command to see the content of the file.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cat .git\/ORIG_HEAD<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b891f47ce06f13456a7e222536ee47ad2fe<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If we used <\/span><i><span style=\"font-weight: 400;\">git reset <\/span><\/i><span style=\"font-weight: 400;\">once again, the log would show the following:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Git log &#8212; oneline feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b8 C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">000f9ae C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can also use <\/span><i><span style=\"font-weight: 400;\">git reflog<\/span><\/i><span style=\"font-weight: 400;\"> to find this info. By using this command, we\u2019ll access a play-by-play listing of switches or changes to references in our local repository. Let\u2019s try it out:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git reflog<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b8 HEAD@{0}: reset: moving to 79768b<\/span><\/p>\n<p><span style=\"font-weight: 400;\">c4533a5 HEAD@{1}: rebase finished: returning to refs\/heads\/feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">c4533a5 HEAD@{2}: rebase C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">64f2047 HEAD@{3}: rebase: C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6a92e7a HEAD@{4}: rebase: checkout master<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b8 HEAD@{5}: checkout: moving from feature to feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">79768b8 HEAD@{6}: commit: C5<\/span><\/p>\n<p><span style=\"font-weight: 400;\">000f9ae HEAD@{7}: checkout: moving from master to feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6a92e7a HEAD@{8}: commit: C4<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 HEAD@{9}: checkout: moving from feature to master<\/span><\/p>\n<p><span style=\"font-weight: 400;\">000f9ae HEAD@{10}: commit: C3<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 HEAD@{11}: checkout: moving from master to feature<\/span><\/p>\n<p><span style=\"font-weight: 400;\">259bf36 HEAD@{12}: commit: C2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">f33ae68 HEAD@{13}: commit: C1<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5043e79 HEAD@{14}: commit (initial): C0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now that we have our list of changes, we can reset to any of the items. All we need to do is use the git reset command followed by the naming format from the log:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">git reset HEAD@{1}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As you can see, making changes in Git becomes much easier once you know that there is an accessible record of the original chain of commits.<\/span><\/p>\n<h3>Git rebase caveats<\/h3>\n<p><span style=\"font-weight: 400;\">While performing git rebase action, it is important to remember that merge conflicts may arise. That usually happens when you have worked on your feature branch for a significant amount of time and diverged from the master branch too much. When you eventually attempt to rebase, the master branch is likely to contain many new commits that may conflict with the changes on your branch. That can easily be avoided by frequently rebasing your feature branch against the master branch and making more frequent commits. If you ever encounter these conflicts, you can always add the<\/span><i><span style=\"font-weight: 400;\"> &#8212; continue<\/span><\/i><span style=\"font-weight: 400;\"> or <\/span><i><span style=\"font-weight: 400;\">&#8212; abort<\/span><\/i><span style=\"font-weight: 400;\"> command line arguments to <\/span><i><span style=\"font-weight: 400;\">git rebase<\/span><\/i><span style=\"font-weight: 400;\"> in order to advance or reset the process.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A more severe caveat is lost commits from the interactive history rewriting process. Using subcommands such as <\/span><i><span style=\"font-weight: 400;\">squash <\/span><\/i><span style=\"font-weight: 400;\">and <\/span><i><span style=\"font-weight: 400;\">drop <\/span><\/i><span style=\"font-weight: 400;\">will remove those commits from your branch\u2019s log. Though it may look like the commits are gone for good, as we have previously mentioned, you can still find them with <\/span><i><span style=\"font-weight: 400;\">git reflog<\/span><\/i><span style=\"font-weight: 400;\">, restore them, and undo git rebase.<\/span><\/p>\n<h2>Final thoughts<\/h2>\n<p><span style=\"font-weight: 400;\">Throughout this article, we have talked about the <\/span><i><span style=\"font-weight: 400;\">git rebase<\/span><\/i><span style=\"font-weight: 400;\"> action. We have covered the common use cases, different rebase modes, and pitfalls, as well as elaborated on how to undo git rebase in case anything unexpected happens.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Git rebase process itself is neither complicated nor dangerous to perform. In fact, one of Git\u2019s main upsides is that it allows you to change and try different things and rapidly undo them if they don\u2019t work the way you expected. The main thing to avoid is to force push the results to a remote branch shared by other users during the history rewriting interactive rebase. That way, you can overwrite other remote users\u2019 work when they attempt to pull changes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Schedule a call to get in touch with our team, or visit our blog pages to find more articles about Git, as well as check other interesting info, such as our take on the reason why you should switch to <\/span><a href=\"https:\/\/alphaefficiency.com\/custom-coded-websites\"><span style=\"font-weight: 400;\">custom-coded websites<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rebase is a Git utility that serves for integrating changes from one branch to another. Along with git merge, it is the only change integration utility. While git merge is a forward-moving process, rebase provides powerful history rewriting features. In a way, we can understand rebase as a merge with Git history. That being said, &hellip; <a href=\"https:\/\/alphaefficiency.com\/git-undo-rebase\">Continued<\/a><\/p>\n","protected":false},"author":31,"featured_media":17531,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[354],"tags":[351],"class_list":["post-17526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-git"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Undo Rebase in Git - Alpha Efficiency.\u2122<\/title>\n<meta name=\"description\" content=\"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/alphaefficiency.com\/git-undo-rebase\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Undo Rebase in Git - Alpha Efficiency.\u2122\" \/>\n<meta property=\"og:description\" content=\"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/alphaefficiency.com\/git-undo-rebase\" \/>\n<meta property=\"og:site_name\" content=\"Alpha Efficiency.\u2122\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/alphaefficiency\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-19T17:15:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Brian Dordevic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@alphaefficiency\" \/>\n<meta name=\"twitter:site\" content=\"@alphaefficiency\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brian Dordevic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase\"},\"author\":{\"name\":\"Brian Dordevic\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/#\\\/schema\\\/person\\\/c0b54b692c44cd01148ff8feabe433b0\"},\"headline\":\"How to Undo Rebase in Git\",\"datePublished\":\"2022-04-19T17:15:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase\"},\"wordCount\":2083,\"image\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/alphaefficiency.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/gitrebase2.png\",\"keywords\":[\"Git\"],\"articleSection\":[\"Web Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase\",\"url\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase\",\"name\":\"How to Undo Rebase in Git - Alpha Efficiency.\u2122\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/alphaefficiency.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/gitrebase2.png\",\"datePublished\":\"2022-04-19T17:15:33+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/#\\\/schema\\\/person\\\/c0b54b692c44cd01148ff8feabe433b0\"},\"description\":\"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/git-undo-rebase#primaryimage\",\"url\":\"https:\\\/\\\/alphaefficiency.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/gitrebase2.png\",\"contentUrl\":\"https:\\\/\\\/alphaefficiency.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/gitrebase2.png\",\"width\":800,\"height\":600},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/#website\",\"url\":\"https:\\\/\\\/alphaefficiency.com\\\/\",\"name\":\"Alpha Efficiency.\u2122\",\"description\":\"Make it. Development and Digital Agency in Chicago.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/alphaefficiency.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/alphaefficiency.com\\\/#\\\/schema\\\/person\\\/c0b54b692c44cd01148ff8feabe433b0\",\"name\":\"Brian Dordevic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g\",\"caption\":\"Brian Dordevic\"},\"sameAs\":[\"https:\\\/\\\/alphaefficiency.com\"],\"url\":\"https:\\\/\\\/alphaefficiency.com\\\/author\\\/briandordevic\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Undo Rebase in Git - Alpha Efficiency.\u2122","description":"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/alphaefficiency.com\/git-undo-rebase","og_locale":"en_US","og_type":"article","og_title":"How to Undo Rebase in Git - Alpha Efficiency.\u2122","og_description":"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.","og_url":"https:\/\/alphaefficiency.com\/git-undo-rebase","og_site_name":"Alpha Efficiency.\u2122","article_publisher":"http:\/\/facebook.com\/alphaefficiency","article_published_time":"2022-04-19T17:15:33+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png","type":"image\/png"}],"author":"Brian Dordevic","twitter_card":"summary_large_image","twitter_creator":"@alphaefficiency","twitter_site":"@alphaefficiency","twitter_misc":{"Written by":"Brian Dordevic","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/alphaefficiency.com\/git-undo-rebase#article","isPartOf":{"@id":"https:\/\/alphaefficiency.com\/git-undo-rebase"},"author":{"name":"Brian Dordevic","@id":"https:\/\/alphaefficiency.com\/#\/schema\/person\/c0b54b692c44cd01148ff8feabe433b0"},"headline":"How to Undo Rebase in Git","datePublished":"2022-04-19T17:15:33+00:00","mainEntityOfPage":{"@id":"https:\/\/alphaefficiency.com\/git-undo-rebase"},"wordCount":2083,"image":{"@id":"https:\/\/alphaefficiency.com\/git-undo-rebase#primaryimage"},"thumbnailUrl":"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png","keywords":["Git"],"articleSection":["Web Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/alphaefficiency.com\/git-undo-rebase","url":"https:\/\/alphaefficiency.com\/git-undo-rebase","name":"How to Undo Rebase in Git - Alpha Efficiency.\u2122","isPartOf":{"@id":"https:\/\/alphaefficiency.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/alphaefficiency.com\/git-undo-rebase#primaryimage"},"image":{"@id":"https:\/\/alphaefficiency.com\/git-undo-rebase#primaryimage"},"thumbnailUrl":"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png","datePublished":"2022-04-19T17:15:33+00:00","author":{"@id":"https:\/\/alphaefficiency.com\/#\/schema\/person\/c0b54b692c44cd01148ff8feabe433b0"},"description":"Which steps should you take to resolve the problem? In today\u2019s article, our web development agency explores ways to undo rebase in Git.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/alphaefficiency.com\/git-undo-rebase"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/alphaefficiency.com\/git-undo-rebase#primaryimage","url":"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png","contentUrl":"https:\/\/alphaefficiency.com\/wp-content\/uploads\/2022\/04\/gitrebase2.png","width":800,"height":600},{"@type":"WebSite","@id":"https:\/\/alphaefficiency.com\/#website","url":"https:\/\/alphaefficiency.com\/","name":"Alpha Efficiency.\u2122","description":"Make it. Development and Digital Agency in Chicago.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/alphaefficiency.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/alphaefficiency.com\/#\/schema\/person\/c0b54b692c44cd01148ff8feabe433b0","name":"Brian Dordevic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ea1ae08900ee894b4d15c1ab314cadcd894a8841f9ec9df42ea48a5b9d64bb7e?s=96&d=blank&r=g","caption":"Brian Dordevic"},"sameAs":["https:\/\/alphaefficiency.com"],"url":"https:\/\/alphaefficiency.com\/author\/briandordevic"}]}},"_links":{"self":[{"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/posts\/17526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/comments?post=17526"}],"version-history":[{"count":0,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/posts\/17526\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/media\/17531"}],"wp:attachment":[{"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/media?parent=17526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/categories?post=17526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alphaefficiency.com\/wp-json\/wp\/v2\/tags?post=17526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}