7

If I have the following commits

38deab3 Bug Fix# 10
f33fb65 Bug Fix# 20
4fa0485 Bug Fix# 30

Why does git rebase -i f33fb65 allow me to edit 38deab3 and not f33fb65? Why do I have to run git rebase -i 4fa0485 to edit f33fb65?

Source.

Community
  • 1
  • 1
Anthony
  • 3,990
  • 23
  • 68
  • 94

4 Answers4

6

You need a base commit to rebase on top of, some commit that will not change, since doing anything other than a pick during an interactive rebase will change the sha id for the commit...unless, of course, you squash/fixup a following commit into the picked commit!

The point is, the rebase command won't know ahead of time how you will rebase your commits, so it needs a base commit that is guaranteed not to be changed by the rebase.

4

git rebase seems to rebase up to the specified commit (whether you do it via commit SHA or e.g. HEAD~4).

So you should use the commit relative notation to select the commit you know and want to tinker with!

$ git rebase -i <SHA>~1

This includes your specified commit (as your going up to the one before it)

Syntax:

$ git rebase -i <SHA>~<number>

This will select from the most recent commit up to not including the <number> more commits that the one you chose!

Example

With an example commit history like so:

  aaa    first commit
  bbb    add a function
  ccc    add terrible colour scheme
  ddd    another function
  eee    my most recent function

And you want to remove that terrible colour scheme change in the commit ccc

You would enter and get the following output.

$ git rebase -i ccc~1

pick  ccc    add terrible colour scheme
pick  ddd    another function
pick  eee    my most recent function
Stefan Collier
  • 4,314
  • 2
  • 23
  • 33
3

Because rebase is applying commits after the one you choose. You are rebasing on this chosen one so you say "take f33fb65 and reapply everything I have after it".

Mateusz
  • 2,287
  • 20
  • 28
3

git rebase -i 4fa0485 means : rebase my current branch (say master) on top of 4fa0485. As such, it will let you edit all commits starting after 4fa0485 until master last commit.

Guillaume Darmont
  • 5,002
  • 1
  • 23
  • 35