Search code examples
gitgit-rebase

continue rebase after `git rebase --abort` and origin remove


I added a new remote to my repo. Then I executed git reset --hard d3d52cee3cf112f30bd4a19611ed34e025d10120 to force HEAD to reset and it worked. I continue working. After other actions, I tried to push my work to origin but it failed. When I try to fix things up I create conflicts and before fixing them I do git rebase --abort and loose everything I commited in between. How can I get back everything that I did before run command git rebase --abort?

Here is pretty much everything I did:

mustaq@Dell /opt/lampp/htdocs/wee $ git push origin master
^C
mustaq@Dell /opt/lampp/htdocs/wee $ git remote add origin 
https://hellomustaq@bitbucket.org/mobilelili/laravel2.git
fatal: remote origin already exists.
mustaq@Dell /opt/lampp/htdocs/wee $ git remote -v
origin  https://sazaldhaka@bitbucket.org/mobilelili/laravelbackend.git 
(fetch)
origin  https://sazaldhaka@bitbucket.org/mobilelili/laravelbackend.git 
(push)
mustaq@Dell /opt/lampp/htdocs/wee $ git remove rm origin
git: 'remove' is not a git command. See 'git --help'.

Did you mean this?
remote
mustaq@Dell /opt/lampp/htdocs/wee $ git remote rm origin
mustaq@Dell /opt/lampp/htdocs/wee $ git remote add origin 
https://hellomustaq@bitbucket.org/mobilelili/laravel2.git
mustaq@Dell /opt/lampp/htdocs/wee $ git add .
mustaq@Dell /opt/lampp/htdocs/wee $ git commit -m "draft"
[master 7afb7d9] draft
6 files changed, 238 insertions(+), 89 deletions(-)
create mode 100644 resources/views/table.blade.php
mustaq@Dell /opt/lampp/htdocs/wee $ git status
On branch master
fatal: Could not open file .git/rebase-merge/done for reading: No such 
file or directory
mustaq@Dell /opt/lampp/htdocs/wee $ git remote -v
origin  https://hellomustaq@bitbucket.org/mobilelili/laravel2.git 
(fetch)
origin  https://hellomustaq@bitbucket.org/mobilelili/laravel2.git 
(push)
mustaq@Dell /opt/lampp/htdocs/wee $  rebase --abort
rebase: command not found
mustaq@Dell /opt/lampp/htdocs/wee $ git  rebase --abort
mustaq@Dell /opt/lampp/htdocs/wee $ git status
On branch master
nothing to commit, working directory clean

Solution

  • You can use git reflog to list the commits that HEAD has pointed to. There you can find the commit before your git rebase --abort and you can force your HEAD to return to it.

    Example:

    $ git reflog
    a9646cd HEAD@{0}: rebase: aborting
    4821905 HEAD@{1}: rebase: checkout test
    a9646cd HEAD@{2}: commit: 3
    177bb91 HEAD@{3}: checkout: moving from test to master
    4821905 HEAD@{4}: commit: 2
    177bb91 HEAD@{5}: checkout: moving from master to test
    177bb91 HEAD@{6}: commit (initial): 1
    
    $ git reset --hard 4821905
    HEAD is now at 4821905 2