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

Adding a commit to the front of my branch?

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
Jan 11, 2016, 13:36 UTC
Message-ID
<CAHd499B8gRMVWnUBZ0aO2RtokYqTm6fO7+7zfbsJNTnKw4MVsQ@mail.gmail.com>
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.

Any advice is greatly appreciated. I'm using Git for Windows 2.7.0.
Next: Stefan Haller
Message 1 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.