Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive rebase for only my commits

Tags:

git

github

While working on my branch i merged the master branch to keep my work up to date with the master.

Now when I want to clean up my commit history (squash / pick) i get all the commits from the master branch as well by git rebase myBranch -i HEAD myfirstcommit

How can I filter out the commits from the master branch, so I can only rearrange my own commits?

like image 807
Manuel Schiller Avatar asked Sep 09 '16 08:09

Manuel Schiller


People also ask

Can you rebase to a specific commit?

In case of git rebase --onto we can change the point where our branch is starting not only to the last commit on parent branch, but we can choose specific commit where we start and also where we finish. This is true not only on one specific branch but for other branches (all valid commits) too.

How do you rebase interactively?

You can run rebase interactively by adding the -i option to git rebase . You must indicate how far back you want to rewrite commits by telling the command which commit to rebase onto. Remember again that this is a rebasing command — every commit in the range HEAD~3..

How do I rebase a commit message?

On the command line, navigate to the repository that contains the commit you want to amend. Use the git rebase -i HEAD~n command to display a list of the last n commits in your default text editor. Replace pick with reword before each commit message you want to change.


Video Answer


1 Answers

After you've merged master into your branch, while staying in your branch, do the following:

git rebase -i master

This will rebase your branch on top of master, taking only new commits, that are in your branch, but not in master.

like image 175
Alexander Guz Avatar answered Oct 11 '22 04:10

Alexander Guz