Git interactive rebase no commits to pick

Lukasz picture Lukasz · Jun 26, 2011 · Viewed 48.6k times · Source

I'm on master and I did rebase -i <my_branch>

Got this:

noop

# Rebase c947bec..7e259d3 onto c947bec
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

I would like to pick some commits not all as some of them are not welcome. Also how do you work when you want to keep some files or changes always 'local' to some branch? Is there some helper like .gitignore?

Answer

CB Bailey picture CB Bailey · Jun 26, 2011

Like a non-interactive rebase, you have to rebase onto a particular commit.

With a non-interactive rebase, if you supply a direct ancestor of the current commit then you aren't changing anything; with an interactive rebase you can edit commits after the commit that you are rebasing onto, even if the commit is a direct ancestor of your current commit but you do have to specify this commit that you want to edit onwards from.

I don't know the details of your situation but you might want something like this:

# Opportunity to edit or prune commits between origin/master and current branch
git rebase -i origin/master

or

# Edit some of the last ten commits
git rebase -i HEAD~10 # Note that ~10 uses a tilde("~") not a dash("-"_) !