Reputation: 1339
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
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
Reputation: 29
It's proppably because u haven't pull changes to local on branch master. Try this:
git checkout master
.git pull
.git checkout {current}
.Git rebase master
.Upvotes: 2
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
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
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
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