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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 11, 2016 at 8:16 AM, John Keeping <john@xxxxxxxxxxxxx> wrote:
> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]