git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: rebase --onto might "loose" commits

From
Nicolas Pitre <nico@cam.org>
Date
Feb 19, 2008, 14:43 UTC
Message-ID
<alpine.LFD.1.00.0802190939240.2732@xanadu.home>
In-Reply-To
<20080219125216.GA10444@atjola.homenet>
On Tue, 19 Feb 2008, Björn Steinbrink wrote:
Show 23 quoted lines
> Hi,
> 
> On 2008.02.19 11:05:40 +0000, Johannes Schindelin wrote:
> > On Tue, 19 Feb 2008, Björn Steinbrink wrote:
> > 
> > > when there's nothing to rebase (ie. upstream..branch is empty), rebase 
> > > fails to find any commits to rebase and correctly says "Nothing to do", 
> > > but when --onto is given, we already did a "reset --hard" to newbase, so 
> > > it already _did_ something.
> > 
> > Yes, it did something.  But if you had that:
> > 
> > A - B - C - D - E
> >   \
> >     F
> > 
> > your HEAD was E, and you said "git rebase --onto F E" what exactly do you
> > want it to do?  There is no commit between E and E, so it rebases
> > _nothing_ onto F.  Which means that F should be your new state.
> 
> Strictly, it's correct, but the "Nothing to do" message is a bit
> misleading (IMHO) and the error message made me think, that it actually
> didn't want to do anything.
Yes, the message should probably be changed in that case.
> I'm a bit unsure about rebase being degraded to a "reset --hard" in this
> case is a good idea. Might be a nice user-protection to make rebase
> abort when there's nothing to rebase and --onto is given. But I don't
> care that much.

The "reset --hard" in that case is really the correct behavior. Rebase might be used like 'git pull --rebase', and if your local branch contains no commits of your own then the 'git reset --hard' is really what needs to happen.

The "user protection" lives in the reflog.
Nicolas
Previous: Björn Steinbrink
Message 4 of 4 in “rebase --onto might "loose" commits”
  1. Björn SteinbrinkFeb 19, 2008
  2. Johannes SchindelinFeb 19, 2008
  3. Björn SteinbrinkFeb 19, 2008
  4. Nicolas PitreFeb 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.