This article will illustrate the procedure to completely cancel a rebase.
How to Completely Cancel a Rebase in Git?
To completely cancel a rebase, first, go to the Git repository. Then, the βgit reset <commit id>β command completely discards the rebase in the current branch.
Check out the mentioned steps to completely cancel a rebase in Git.
Step 1: Open Git Terminal
First, launch the βGit Bashβ Git terminal from the Start menu:
Step 2: Go to Git Repository
Go to the Git repository via the βcdβ command:
Step 3: Move to Branch to Commit Changes
Move to the branch in which you want to commit changes using the βgit checkoutβ command:
Step 4: Generate New File
Generate the new file by utilizing the βtouchβ command:
Step 5: Add Untracked File to Staging Index
Add the untracked changes to the tracking index through the provided command:
Check the repository status to verify if the changes are added to the staging index or not:
It can be observed that the changes are successfully added to the staging index:
Step 6: Commit Tracked Changes
In the next step, track the committed changes using the βgit commitβ command:
Step 7: Switch Branch
Now, move to the branch in which you want to rebase the commits of the current branch using the βgit checkoutβ command:
After that, use the βgit reflogβ command to check the Git logs along with references and commit id to verify if the changes are added to log references and note the current position of HEAD:
Step 8: Rebase Branch
Next, rebase the other branch in the current branch to access the commit of the other branch using the βgit rebase <branch-name>β command:
After rebasing, again check out the Git log using βgit reflogβ to verify whether the rebasing of the branch takes place or not:
The output shows that we have successfully rebased the commits of another branch. Now, note the previous commit id to completely cancel the rebase:
Step 9: Completely Cancel a Rebase
Next, utilize the βgit resetβ command along with the previous commit id to revert the changes and cancel the rebase completely:
Again, check the log references to see the position of HEAD:
It can be seen that we have successfully reverted a rebase:
As an alternative, you can confirm the cancellation of rebase by checking out the logs of the current branch:
You can see that the current branch does not contain any commits from the other branch:
We have taught you the method to cancel a rebase in Git completely.
Conclusion
To completely cancel the Git rebase, open the Git repository, and commit the tracked changes using the βgit commitβ command. After that, move to the branch in which you would like to completely cancel the rebase using the βgit checkout <branch-name>β command. Lastly, use the βgit reset <commit-id>β command to undo the rebase, where commit id is the id of the commit that came before the rebase. This write-up has demonstrated how to cancel a rebase completely.