{"thread":{"id":"41160","subject":"Adding a commit to the front of my branch?","startedAt":"2016-01-11T13:36:25Z","lastAt":"2016-01-13T17:19:46Z","messageCount":7,"participants":["Robert Dailey","John Keeping","Stefan Haller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"275640","messageId":"CAHd499B8gRMVWnUBZ0aO2RtokYqTm6fO7+7zfbsJNTnKw4MVsQ@mail.gmail.com","threadId":"41160","inReplyTo":null,"subject":"Adding a commit to the front of my branch?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-01-11T13:36:25Z","receivedAt":"2016-01-11T13:36:25Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"Normally to add commits on my branch, I perform an interactive rebase:\n\n$ git rebase -i origin/master\n\nI mark the commit I want to put the new commit on top of as 'edit'.\nHowever, if I want to add a commit to the front of my branch, I don't\nreally have a commit to mark as \"edit\". I tried to be tricky with\nthis, and did:\n\n$ git rebase -i origin/master^\n\nHowever this doesn't work if my merge-base is a merge commit. I get a\nton of superfluous commits in my TODO file.\n\nIs there a built-in mechanism I can use, with relative ease, to\naccomplish this goal? At the moment I have to run a series of a couple\nof commands to do this, namely mark the oldest commit on my branch as\n'edit', reset it, stash it, add new commit, pop stash, commit again,\netc.\n\nNormally I'd add a new tip commit and reorder it to accomplish this,\nhowever commits on my branch already alter this code and I don't want\nto create unnecessary conflicts during rebase. The patch needs to be\nbased on merge-base.\n\nAny advice is greatly appreciated. I'm using Git for Windows 2.7.0.\n"},{"id":"275642","messageId":"1mgv8hf.iib6fg1g9uszaM%lists@haller-berlin.de","threadId":"41160","inReplyTo":"CAHd499B8gRMVWnUBZ0aO2RtokYqTm6fO7+7zfbsJNTnKw4MVsQ@mail.gmail.com","subject":"Re: Adding a commit to the front of my branch?","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2016-01-11T14:11:25Z","receivedAt":"2016-01-11T14:11:25Z","isPatch":false,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Robert Dailey <rcdailey.lists@gmail.com> wrote:\n\n> Normally to add commits on my branch, I perform an interactive rebase:\n> \n> $ git rebase -i origin/master\n> \n> I mark the commit I want to put the new commit on top of as 'edit'.\n> However, if I want to add a commit to the front of my branch, I don't\n> really have a commit to mark as \"edit\".\n\nInstead of marking commits as edit, I usually add \"x false\" at the place\nwhere I want to add a commit. With this I find it easier to see where\nthe new commit goes, and it also works before the first commit.\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"275641","messageId":"20160111141612.GK14056@serenity.lan","threadId":"41160","inReplyTo":"CAHd499B8gRMVWnUBZ0aO2RtokYqTm6fO7+7zfbsJNTnKw4MVsQ@mail.gmail.com","subject":"Re: Adding a commit to the front of my branch?","fromName":"John Keeping","fromEmail":"john@keeping.me.uk","sentAt":"2016-01-11T14:16:12Z","receivedAt":"2016-01-11T14:16:12Z","isPatch":false,"sender":{"key":"john@keeping.me.uk","avatar":"https://avatars.githubusercontent.com/u/1702081?v=4"},"body":"On Mon, Jan 11, 2016 at 07:36:25AM -0600, Robert Dailey wrote:\n> Normally to add commits on my branch, I perform an interactive rebase:\n> \n> $ git rebase -i origin/master\n> \n> I mark the commit I want to put the new commit on top of as 'edit'.\n> However, if I want to add a commit to the front of my branch, I don't\n> really have a commit to mark as \"edit\". I tried to be tricky with\n> this, and did:\n> \n> $ git rebase -i origin/master^\n> \n> However this doesn't work if my merge-base is a merge commit. I get a\n> ton of superfluous commits in my TODO file.\n> \n> Is there a built-in mechanism I can use, with relative ease, to\n> accomplish this goal? At the moment I have to run a series of a couple\n> of commands to do this, namely mark the oldest commit on my branch as\n> 'edit', reset it, stash it, add new commit, pop stash, commit again,\n> etc.\n> \n> Normally I'd add a new tip commit and reorder it to accomplish this,\n> however commits on my branch already alter this code and I don't want\n> to create unnecessary conflicts during rebase. The patch needs to be\n> based on merge-base.\n\nHave you considered creating a new (temporary) branch based on master,\nadding the new commit there and inserting \"pick $new_commit_sha1\" at the\nstart of the instruction sheet when rebasing the original branch?\n"},{"id":"275912","messageId":"CAHd499Adtc3qMgvXywONpgK0Z5NzGMnZ-=5akbLo+i6m2oJpYA@mail.gmail.com","threadId":"41160","inReplyTo":"1mgv8hf.iib6fg1g9uszaM%lists@haller-berlin.de","subject":"Re: Adding a commit to the front of my branch?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-01-13T16:18:19Z","receivedAt":"2016-01-13T16:18:19Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:\n> Robert Dailey <rcdailey.lists@gmail.com> wrote:\n>\n>> Normally to add commits on my branch, I perform an interactive rebase:\n>>\n>> $ git rebase -i origin/master\n>>\n>> I mark the commit I want to put the new commit on top of as 'edit'.\n>> However, if I want to add a commit to the front of my branch, I don't\n>> really have a commit to mark as \"edit\".\n>\n> Instead of marking commits as edit, I usually add \"x false\" at the place\n> where I want to add a commit. With this I find it easier to see where\n> the new commit goes, and it also works before the first commit.\n\nWhat do you mean \"x false\"? I'm not familiar with this. Can you explain?\n"},{"id":"275913","messageId":"CAHd499Ay7cCANQavNpYN7EQDmeHgvZvVS2FP=udEVxf8KoBKcg@mail.gmail.com","threadId":"41160","inReplyTo":"20160111141612.GK14056@serenity.lan","subject":"Re: Adding a commit to the front of my branch?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-01-13T16:21:42Z","receivedAt":"2016-01-13T16:21:42Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Mon, Jan 11, 2016 at 8:16 AM, John Keeping <john@keeping.me.uk> wrote:\n> On Mon, Jan 11, 2016 at 07:36:25AM -0600, Robert Dailey wrote:\n>> Normally to add commits on my branch, I perform an interactive rebase:\n>>\n>> $ git rebase -i origin/master\n>>\n>> I mark the commit I want to put the new commit on top of as 'edit'.\n>> However, if I want to add a commit to the front of my branch, I don't\n>> really have a commit to mark as \"edit\". I tried to be tricky with\n>> this, and did:\n>>\n>> $ git rebase -i origin/master^\n>>\n>> However this doesn't work if my merge-base is a merge commit. I get a\n>> ton of superfluous commits in my TODO file.\n>>\n>> Is there a built-in mechanism I can use, with relative ease, to\n>> accomplish this goal? At the moment I have to run a series of a couple\n>> of commands to do this, namely mark the oldest commit on my branch as\n>> 'edit', reset it, stash it, add new commit, pop stash, commit again,\n>> etc.\n>>\n>> Normally I'd add a new tip commit and reorder it to accomplish this,\n>> however commits on my branch already alter this code and I don't want\n>> to create unnecessary conflicts during rebase. The patch needs to be\n>> based on merge-base.\n>\n> Have you considered creating a new (temporary) branch based on master,\n> adding the new commit there and inserting \"pick $new_commit_sha1\" at the\n> start of the instruction sheet when rebasing the original branch?\n\nI think this functions but it lacks the simplicity I'm looking for. I\nmentioned I already had workarounds, what I'm really looking for is a\nbuilt-in mechanism to do this.\n\nWith your solution, I'd be doing this (best I can guess):\n\n1. $ git checkout -b temp [merge-base]\n2. hack hack hack\n3. $ git commit -am 'hacking'\n4. $ git checkout -\n5. $ git rebase -i [merge-base]\n6. Add the pick you mentioned here, at the top\n\nStill a bit messy and lots of steps. More steps might be necessary\nthan I've shown, to establish the [merge-base] SHA1 to use.\n"},{"id":"275918","messageId":"1mgz4yx.94yt5g12q9hidM%lists@haller-berlin.de","threadId":"41160","inReplyTo":"CAHd499Adtc3qMgvXywONpgK0Z5NzGMnZ-=5akbLo+i6m2oJpYA@mail.gmail.com","subject":"Re: Adding a commit to the front of my branch?","fromName":"Stefan Haller","fromEmail":"lists@haller-berlin.de","sentAt":"2016-01-13T16:40:41Z","receivedAt":"2016-01-13T16:40:41Z","isPatch":false,"sender":{"key":"lists@haller-berlin.de","avatar":null},"body":"Robert Dailey <rcdailey.lists@gmail.com> wrote:\n\n> On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:\n> > Robert Dailey <rcdailey.lists@gmail.com> wrote:\n> >\n> >> Normally to add commits on my branch, I perform an interactive rebase:\n> >>\n> >> $ git rebase -i origin/master\n> >>\n> >> I mark the commit I want to put the new commit on top of as 'edit'.\n> >> However, if I want to add a commit to the front of my branch, I don't\n> >> really have a commit to mark as \"edit\".\n> >\n> > Instead of marking commits as edit, I usually add \"x false\" at the place\n> > where I want to add a commit. With this I find it easier to see where\n> > the new commit goes, and it also works before the first commit.\n> \n> What do you mean \"x false\"? I'm not familiar with this. Can you explain?\n\n\"x\" is a shorthand for \"exec\" (just like \"p\" is a shorthand for \"pick\",\nfor instance). \"exec\" will execute an arbitrary shell command, and stop\nwhen that shell command fails with an exit code not equal to zero.\n\"false\" is a shell command that does nothing except return a non-zero\nexit code, so \"x false\" just stops and waits for you to \"fix\" something.\nAt that point you can make additional commits, and then \"git rebase\n--continue\" to go on.\n\n\n-- \nStefan Haller\nBerlin, Germany\nhttp://www.haller-berlin.de/\n"},{"id":"275934","messageId":"CAHd499A67diDmBB3cO_SYXNaZnohcxNtaQpmDAomwToG+MMOvw@mail.gmail.com","threadId":"41160","inReplyTo":"1mgz4yx.94yt5g12q9hidM%lists@haller-berlin.de","subject":"Re: Adding a commit to the front of my branch?","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2016-01-13T17:19:46Z","receivedAt":"2016-01-13T17:19:46Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"On Wed, Jan 13, 2016 at 10:40 AM, Stefan Haller <lists@haller-berlin.de> wrote:\n> Robert Dailey <rcdailey.lists@gmail.com> wrote:\n>\n>> On Mon, Jan 11, 2016 at 8:11 AM, Stefan Haller <lists@haller-berlin.de> wrote:\n>> > Robert Dailey <rcdailey.lists@gmail.com> wrote:\n>> >\n>> >> Normally to add commits on my branch, I perform an interactive rebase:\n>> >>\n>> >> $ git rebase -i origin/master\n>> >>\n>> >> I mark the commit I want to put the new commit on top of as 'edit'.\n>> >> However, if I want to add a commit to the front of my branch, I don't\n>> >> really have a commit to mark as \"edit\".\n>> >\n>> > Instead of marking commits as edit, I usually add \"x false\" at the place\n>> > where I want to add a commit. With this I find it easier to see where\n>> > the new commit goes, and it also works before the first commit.\n>>\n>> What do you mean \"x false\"? I'm not familiar with this. Can you explain?\n>\n> \"x\" is a shorthand for \"exec\" (just like \"p\" is a shorthand for \"pick\",\n> for instance). \"exec\" will execute an arbitrary shell command, and stop\n> when that shell command fails with an exit code not equal to zero.\n> \"false\" is a shell command that does nothing except return a non-zero\n> exit code, so \"x false\" just stops and waits for you to \"fix\" something.\n> At that point you can make additional commits, and then \"git rebase\n> --continue\" to go on.\n\nOh, this is pretty neat! So I assume it will stop BEFORE a patch is\napplied, unlike edit? I will try this next time. However it would be\ngreat to see a new 'insert' command for the TODO file, that will let\nyou insert a commit at that point (i.e. it stops before the marked\ncommit is applied).\n\nThanks for the help.\n"}]}