Search code examples
gitgit-rebase

How to perform a git rebase of local commits


A common scenario is to perform an interactive rebase of the local git commits before pushing to a repository. One way of doing this is to find the number of local commits and run the command (in this example 3 local commits)

git rebase -i HEAD~3

Is there a way of saving the need to find out the number of local commits beforehand, and directly run a command that means git rebase -i 'commits not yet pushed'.

Edit: Let me elaborate by giving a specific scenario. I perform three commits:

Commit change A
Commit change B
Commit change C

At this point I realize that the changes in C belong with the changes in A, so I want to rebase to give me what I want:

Commit containing A + C
Commit containing B

At this point, there has been no push. Seeing as I cannot remember how many changes the change C was, I do a

git log @{u}..

and determine that I have three changes. So now I want to do a

git rebase -i HEAD~3

Or, as @cosimo93 points out, I can simply do

git rebase -i

Solution

  • You can just try:

    git rebase -i