简体   繁体   中英

Not able to push after git rebase

I am new to git and i want to use the git rebase feature to merge my few commits. However After after I run the rebase command and merge the commits, I am not able to push the changes.

On branch master Your branch and 'origin/master' have diverged, and have 1 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours)

nothing to commit, working directory clean

Following is the process I am following.

  1. Following is the output of the git log --pretty=oneline command 7014f2b4f01c40868f488b0cc28742d179b6c404 Third Commit 64504dfab9f37250760a0862199e0291fc1bce6e Second Commit e4869ace429dc8f60ec1862bbfb19330eefbfe6a First Commit

  2. Second command - git rebase -i HEAD~2
    pick 64504df Second Commit
    squash 7014f2b Third Commit
    I am getting following output after rebase is done, and after this not able to push changes.

    [detached HEAD 35b14b0] Second Commit 1 file changed, 3 insertions(+), 1 deletion(-) Successfully rebased and updated refs/heads/master.

Output of git log --oneline --graph --decorate HEAD...@{u}

* 454f5f4 (HEAD, master) Second Commit 
* 7014f2b (origin/master) Third Commit 
* 64504df Second Commit 

Please not that all the changes are also pushed to github as well.

Looks like you already pushed your two changes to origin.

Now the rebase throws away the last two commits and replaces them by a single combined commit.

Therefore the branches "diverted". The remote repository contains two commits where your local repository contains a single commit. Normally you are only able to push if you are only adding new commits. Therefore git complains.

General rule: Never rebase commits you already pushed.

If you simply want to push your changes use git pull or git pull --rebase . This will merge or rebase you local changes on top of the remote changes. Afterwards you should be able to push without problems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM