Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git rebase -i a branch onto itself

I had the following in my repo

Master---
     \
       Next-->Commit A.1,Commit A.2,Commit A.3 --......

I want to fix-up the A.* commits into one commit describing the feature A. I tried git rebase -i origin next, but that didn't work how I expected. Is there any way of accomplishing this?

I thought of creating a branch foo, which is essentially next, and then rebase next onto foo followed by merge/delete foo. However, this seems sloppy.

like image 294
ndp Avatar asked Oct 22 '12 08:10

ndp


People also ask

How do I merge a branch by itself?

You can do this two ways (when getting the changes from the remote server): git fetch; git rebase. git pull --rebase.

What does git rebase onto do?

What is git rebase? From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.

How do I rebase my branch?

To rebase, make sure you have all the commits you want in the rebase in your master branch. Check out the branch you want to rebase and type git rebase master (where master is the branch you want to rebase on).


1 Answers

You just need to do:

git rebase -i <COMMIT-ISH>

... where <COMMIT-ISH> is some way of referring to the commit marked Master in your diagram. If there's a branch pointing to that point (probably master or origin/master) then git log --decorate will show that.

like image 141
Mark Longair Avatar answered Oct 31 '22 12:10

Mark Longair