10

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.

maxhallinan
  • 1,117
  • 1
  • 12
  • 26
  • "I rebased my branch which had the effect of putting some commits on top of my own." Not the other way around (put your commits on top of those of the branch onto which you rebased)? – das-g Jul 26 '16 at 21:30
  • 1
    "so hard reset" hard reset which branch to what revision? – das-g Jul 26 '16 at 21:31
  • 1
    [Undo your bad rebase](http://stackoverflow.com/q/134882/6194839) then [Rebase Properly](http://stackoverflow.com/q/7929369/6194839) – Bryce Drew Jul 26 '16 at 21:52
  • Possible duplicate of [When do you use git rebase instead of git merge?](http://stackoverflow.com/questions/804115/when-do-you-use-git-rebase-instead-of-git-merge) – Bryce Drew Jul 26 '16 at 21:53
  • This [answer](https://stackoverflow.com/questions/14893399/rebase-feature-branch-onto-another-feature-branch) would be helpful to understand how re basing works – Erangad Jun 30 '18 at 03:06

3 Answers3

1

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

git checkout b
git rebase --force-rebase a
nobody
  • 234
  • 4
  • 11
0

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

Nurio Fernández
  • 385
  • 2
  • 16
-1

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

git reset --hard origin/your-branch-name
Nurio Fernández
  • 385
  • 2
  • 16