Just Rudy
Just Rudy

Reputation: 700

Ran rebase in wrong direction?

I have master and a search branch. I've been making all these changes in my search branch, and committing to it. Then I'd run git push origin search.

I have been doing this for months, but now I'd like to have these changes reflect in master, basically catch master up to search.

I read responses here indicating that rebase may be the answer I'm looking for. Upon executing git checkout master and then git rebase master search, there were a bunch of conflicts that I had to resolve. Once resolved, I finished with a final git rebase --continue and it completed.

However, now I'm seeing the status for search is up to date, but master shows a status message saying "Your branch and 'origin/search' have diverged" and suggesting that I do a git pull from master to merge the remote branch (search?) into mine (master?). Upon reading some of the answers here, I'm still a bit confused over this.

Question 1: Did I run the rebase command backward; should it have been git rebase search master?

Question 2: What should I do now? Can I do a rollback (git revert)?

Upvotes: 2

Views: 1962

Answers (1)

Jonathan.Brink
Jonathan.Brink

Reputation: 25383

I believe you have performed your rebase correctly. To verify, see if the parent commit of your search branch matches the tip of the master branch (git rev-parse search~ and git rev-parse master)

You are seeing that message because your local search branch has diverged from the remote version of the search branch...meaning that they no longer have a common commit...even though the content between the two branches is likely almost the same (minus the conflict resolution changes).

This message is entirely expected...you have (for very good reason) re-written the history of your search branch, giving it a different base commit.

So, if you are wanting to push your latest search changes to your remote search branch you will need to do a "force push" like this:

git push --force origin search

Git is forcing you to do a force push because if other developers were also working off of the search branch they would also become diverged.

But, after you merge into master it won't matter that your search branch has been changed in this way and the folks using the master branch will be happy that you improved the clarity of the overall commit history by rebasing before you merge to the common branch.

Here is more information about force pushing: https://git-scm.com/docs/git-push#git-push--f

Upvotes: 1

Related Questions