maxhallinan
maxhallinan

Reputation: 1339

How to rebase when it says that current branch is up to date even though it isn't?

I rebased my branch which had the effect of putting some commits on top of my own. Then realized I had forgotten to squash some commits, so hard reset and squashed. Now I need to bring those commits back. But rebasing again tells me that the current branch is up to date, even though it isn't. Is there a way to fix this?

Edit:

There are two branches: a and b. Both are branched from master. Both are up to date with master. Branch a has some changes. I want branch b to have those changes too. I rebased branch a on to b. The latest commit was from branch a. I meant to squash the three commits before that commit. I hard reset to before the latest commit. Then I squashed. Now I want to get back that latest commit in a way that won't cause headaches when the time comes to merge branch b to master.

I've tried reflog and git reset --hard HEAD@{n} but same problem: Current branch is up to date.

Upvotes: 20

Views: 27281

Answers (6)

lam vu Nguyen
lam vu Nguyen

Reputation: 641

in my case, I have 4 branches as below

read

|............HEAD -> write

|............cpu

|........../

master

it says that current branch is up to date when I run git rebase master

write branch has already rebased master, but I want it to be

read

|............cpu

|............HEAD -> write

|........../

master

so I run git rebase -i HEAD~2 then manually remove changes in cpu... =))) I know it seem silly

Upvotes: 0

Mateusz
Mateusz

Reputation: 29

It's proppably because u haven't pull changes to local on branch master. Try this:

  1. Commit all changes on your current branch.
  2. Switch to master git checkout master.
  3. Pull changes git pull.
  4. Switch to "current" branch git checkout {current}.
  5. Try Git rebase master.

Upvotes: 2

Mathieu CAROFF
Mathieu CAROFF

Reputation: 1502

In my case, the issue was simply that master was outdated compared to origin/master, so I had to run:

git branch -f master origin/master

Upvotes: 3

nobody
nobody

Reputation: 156

In my case --force-rebase helped. I guess, in your case it would be:

git checkout b
git rebase --force-rebase a

Upvotes: 10

Nurio Fernández
Nurio Fernández

Reputation: 516

In case you didn't push that rebase, you can reset hard to the remote repository branch.

git reset --hard origin/your-branch-name

Upvotes: 0

Nurio Fernández
Nurio Fernández

Reputation: 516

In case you have your commit's id, you can use the interactive rebase and add them manually.

Assuming your origin branch was master, you can do:

git rebase -i master

And you will receive something like this:

pick 000000 Name of a commit
pick 000001 Name of another commit

You can add another pick bbbbbb with the commitId you want to add, something like

pick 000000 Name of a commit
pick bbbbbb
pick 000001 Name of another commit

If you want to squash a commit, you can do:

pick 000000 Name of a commit
squash bbbbbb
pick 000001 Name of another commit

The squash operation will append your lower commit to the previous one, that means the 00000

Upvotes: 0

Related Questions