git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Adding a commit to the front of my branch?
@ 2016-01-11 13:36 Robert Dailey
  2016-01-11 14:11 ` Stefan Haller
  2016-01-11 14:16 ` John Keeping
  0 siblings, 2 replies; 7+ messages in thread
From: Robert Dailey @ 2016-01-11 13:36 UTC (permalink / raw)
  To: Git

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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-11 13:36 Adding a commit to the front of my branch? Robert Dailey
@ 2016-01-11 14:11 ` Stefan Haller
  2016-01-13 16:18   ` Robert Dailey
  2016-01-11 14:16 ` John Keeping
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Haller @ 2016-01-11 14:11 UTC (permalink / raw)
  To: Robert Dailey, Git

Robert Dailey <rcdailey.lists@gmail.com> 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".

Instead of marking commits as edit, I usually add "x false" at the place
where I want to add a commit. With this I find it easier to see where
the new commit goes, and it also works before the first commit.


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-11 13:36 Adding a commit to the front of my branch? Robert Dailey
  2016-01-11 14:11 ` Stefan Haller
@ 2016-01-11 14:16 ` John Keeping
  2016-01-13 16:21   ` Robert Dailey
  1 sibling, 1 reply; 7+ messages in thread
From: John Keeping @ 2016-01-11 14:16 UTC (permalink / raw)
  To: Robert Dailey; +Cc: Git

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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-11 14:11 ` Stefan Haller
@ 2016-01-13 16:18   ` Robert Dailey
  2016-01-13 16:40     ` Stefan Haller
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Dailey @ 2016-01-13 16:18 UTC (permalink / raw)
  To: Stefan Haller; +Cc: Git

On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:
> Robert Dailey <rcdailey.lists@gmail.com> 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".
>
> Instead of marking commits as edit, I usually add "x false" at the place
> where I want to add a commit. With this I find it easier to see where
> the new commit goes, and it also works before the first commit.

What do you mean "x false"? I'm not familiar with this. Can you explain?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-11 14:16 ` John Keeping
@ 2016-01-13 16:21   ` Robert Dailey
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dailey @ 2016-01-13 16:21 UTC (permalink / raw)
  To: John Keeping; +Cc: Git

On Mon, Jan 11, 2016 at 8:16 AM, John Keeping <john@keeping.me.uk> 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.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-13 16:18   ` Robert Dailey
@ 2016-01-13 16:40     ` Stefan Haller
  2016-01-13 17:19       ` Robert Dailey
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Haller @ 2016-01-13 16:40 UTC (permalink / raw)
  To: Robert Dailey; +Cc: Git

Robert Dailey <rcdailey.lists@gmail.com> wrote:

> On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:
> > Robert Dailey <rcdailey.lists@gmail.com> 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".
> >
> > Instead of marking commits as edit, I usually add "x false" at the place
> > where I want to add a commit. With this I find it easier to see where
> > the new commit goes, and it also works before the first commit.
> 
> What do you mean "x false"? I'm not familiar with this. Can you explain?

"x" is a shorthand for "exec" (just like "p" is a shorthand for "pick",
for instance). "exec" will execute an arbitrary shell command, and stop
when that shell command fails with an exit code not equal to zero.
"false" is a shell command that does nothing except return a non-zero
exit code, so "x false" just stops and waits for you to "fix" something.
At that point you can make additional commits, and then "git rebase
--continue" to go on.


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Adding a commit to the front of my branch?
  2016-01-13 16:40     ` Stefan Haller
@ 2016-01-13 17:19       ` Robert Dailey
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dailey @ 2016-01-13 17:19 UTC (permalink / raw)
  To: Stefan Haller; +Cc: Git

On Wed, Jan 13, 2016 at 10:40 AM, Stefan Haller <lists@haller-berlin.de> wrote:
> Robert Dailey <rcdailey.lists@gmail.com> wrote:
>
>> On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:
>> > Robert Dailey <rcdailey.lists@gmail.com> 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".
>> >
>> > Instead of marking commits as edit, I usually add "x false" at the place
>> > where I want to add a commit. With this I find it easier to see where
>> > the new commit goes, and it also works before the first commit.
>>
>> What do you mean "x false"? I'm not familiar with this. Can you explain?
>
> "x" is a shorthand for "exec" (just like "p" is a shorthand for "pick",
> for instance). "exec" will execute an arbitrary shell command, and stop
> when that shell command fails with an exit code not equal to zero.
> "false" is a shell command that does nothing except return a non-zero
> exit code, so "x false" just stops and waits for you to "fix" something.
> At that point you can make additional commits, and then "git rebase
> --continue" to go on.

Oh, this is pretty neat! So I assume it will stop BEFORE a patch is
applied, unlike edit? I will try this next time. However it would be
great to see a new 'insert' command for the TODO file, that will let
you insert a commit at that point (i.e. it stops before the marked
commit is applied).

Thanks for the help.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-01-13 17:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-11 13:36 Adding a commit to the front of my branch? Robert Dailey
2016-01-11 14:11 ` Stefan Haller
2016-01-13 16:18   ` Robert Dailey
2016-01-13 16:40     ` Stefan Haller
2016-01-13 17:19       ` Robert Dailey
2016-01-11 14:16 ` John Keeping
2016-01-13 16:21   ` Robert Dailey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).