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

Re: Adding a commit to the front of my branch?

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Jan 13, 2016, 16:21 UTC
Message-ID
<CAHd499Ay7cCANQavNpYN7EQDmeHgvZvVS2FP=udEVxf8KoBKcg@mail.gmail.com>
In-Reply-To
<20160111141612.GK14056@serenity.lan>
On Mon, Jan 11, 2016 at 8:16 AM, John Keeping <john@keeping.me.uk> wrote:
Show 29 quoted lines
> On Mon, Jan 11, 2016 at 07:36:25AM -0600, Robert Dailey wrote:
>> Normally to add commits on my branch, I perform an interactive rebase:
>>
>> $ git rebase -i origin/master
>>
>> I mark the commit I want to put the new commit on top of as 'edit'.
>> However, if I want to add a commit to the front of my branch, I don't
>> really have a commit to mark as "edit". I tried to be tricky with
>> this, and did:
>>
>> $ git rebase -i origin/master^
>>
>> However this doesn't work if my merge-base is a merge commit. I get a
>> ton of superfluous commits in my TODO file.
>>
>> Is there a built-in mechanism I can use, with relative ease, to
>> accomplish this goal? At the moment I have to run a series of a couple
>> of commands to do this, namely mark the oldest commit on my branch as
>> 'edit', reset it, stash it, add new commit, pop stash, commit again,
>> etc.
>>
>> Normally I'd add a new tip commit and reorder it to accomplish this,
>> however commits on my branch already alter this code and I don't want
>> to create unnecessary conflicts during rebase. The patch needs to be
>> based on merge-base.
>
> Have you considered creating a new (temporary) branch based on master,
> adding the new commit there and inserting "pick $new_commit_sha1" at the
> start of the instruction sheet when rebasing the original branch?

I think this functions but it lacks the simplicity I'm looking for. I mentioned I already had workarounds, what I'm really looking for is a built-in mechanism to do this.

With your solution, I'd be doing this (best I can guess):
1. $ git checkout -b temp [merge-base]
2. hack hack hack
3. $ git commit -am 'hacking'
4. $ git checkout -
5. $ git rebase -i [merge-base]
6. Add the pick you mentioned here, at the top

Still a bit messy and lots of steps. More steps might be necessary than I've shown, to establish the [merge-base] SHA1 to use.

Previous: John Keeping
Message 7 of 7 in “Adding a commit to the front of my branch?”
  1. Robert DaileyJan 11, 2016
  2. Stefan HallerJan 11, 2016
  3. Robert DaileyJan 13, 2016
  4. Stefan HallerJan 13, 2016
  5. Robert DaileyJan 13, 2016
  6. John KeepingJan 11, 2016
  7. Robert DaileyJan 13, 2016

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.