{"thread":{"id":"46865","subject":"will git rebase has side effect","startedAt":"2017-10-01T13:23:30Z","lastAt":"2017-10-01T16:11:58Z","messageCount":4,"participants":["Yubin Ruan","Kevin Daudt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"329279","messageId":"CAJYFCiNj22McSaKcCVMDVgah5cAqHYHja_b2jj6VAaAA=zSM1g@mail.gmail.com","threadId":"46865","inReplyTo":null,"subject":"will git rebase has side effect","fromName":"Yubin Ruan","fromEmail":"ablacktshirt@gmail.com","sentAt":"2017-10-01T13:23:23Z","receivedAt":"2017-10-01T13:23:30Z","isPatch":false,"sender":{"key":"ablacktshirt@gmail.com","avatar":null},"body":"Suppose that I have such a history of commit locally:\n\nA --> B --> C --> D\n\nIf I then add a few more commits locally\n\nA --> B --> C --> D --> E --> F --> G\n\nAnd then I do a rebase and squash F and G into one single commit H.\nWhat side effect will this rebase have? How will this affect \"git push\norigin master\"?\n\nYubin\n"},{"id":"329280","messageId":"20171001141719.GB20406@alpha.vpn.ikke.info","threadId":"46865","inReplyTo":"20171001134155.GA20406@alpha.vpn.ikke.info","subject":"Re: will git rebase has side effect","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2017-10-01T14:17:19Z","receivedAt":"2017-10-01T14:17:26Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"Forgot to cc the mailing list.\n\nOn Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:\n> Suppose that I have such a history of commit locally:\n> \n> A --> B --> C --> D\n> \n> If I then add a few more commits locally\n> \n> A --> B --> C --> D --> E --> F --> G\n> \n> And then I do a rebase and squash F and G into one single commit H.\n> What side effect will this rebase have? How will this affect \"git push\n> origin master\"?\n> \n> Yubin\n\nHello Yubin,\n\nSo the situation is this:\n\n            [origin/master]\n                  |\nA --> B --> C --> D --> E --> F --> G\n                                    |\n                                 [master] \n\nThen you squash (F' is the result of squashing F and G):\n\n            [origin/master]\n                  |\nA --> B --> C --> D --> E --> F'\n                              |\n                           [master] \n\nWhen you want to push now, it's just as if you just created just two\ncommits in the first place, and you can just push normally (assuming no\none else has pushed in the mean time.\n\nThe situation is different when you have pushed already:\n\n                              [origin/master]\n                                    |\nA --> B --> C --> D --> E --> F --> G\n                                    |\n                                 [master] \n\nThen after you squash, the history would look as follows:\n\n                              [origin/master]\n                                    |\nA --> B --> C --> D --> E --> F --> G\n                         \\\n                          --> F'\n                              |\n                           [master] \n\nThis sitation would look to git like you created F', and someone else\nhad pushed F and G. It will reject the push, saying you would need to\nmerge these changes first (but you don't want this, because you are\nmerging the same changes together).\n\nTo solve this, you can use git push --force-with-lease=master origin,\nwhich will force the push, overwriting the history the remote already\nhad.\n\nHope this helps, Kevin.\n\nnb. --force-with-lease is a safer version of just (-f|--force), because\nit will prevent you from overwriting history you don't have locally, for\nexample when someone else did push already.\n\n\n"},{"id":"329304","messageId":"CAJYFCiNmDpNNdbRsN-F-mOtcOEVruawEKUtA9h3BAFZZWKStsQ@mail.gmail.com","threadId":"46865","inReplyTo":"20171001141719.GB20406@alpha.vpn.ikke.info","subject":"Re: will git rebase has side effect","fromName":"Yubin Ruan","fromEmail":"ablacktshirt@gmail.com","sentAt":"2017-10-01T16:06:38Z","receivedAt":"2017-10-01T16:06:44Z","isPatch":false,"sender":{"key":"ablacktshirt@gmail.com","avatar":null},"body":"2017-10-01 22:17 GMT+08:00 Kevin Daudt <me@ikke.info>:\n> Forgot to cc the mailing list.\n>\n> On Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:\n>> Suppose that I have such a history of commit locally:\n>>\n>> A --> B --> C --> D\n>>\n>> If I then add a few more commits locally\n>>\n>> A --> B --> C --> D --> E --> F --> G\n>>\n>> And then I do a rebase and squash F and G into one single commit H.\n>> What side effect will this rebase have? How will this affect \"git push\n>> origin master\"?\n>>\n>> Yubin\n>\n> Hello Yubin,\n>\n> So the situation is this:\n>\n>             [origin/master]\n>                   |\n> A --> B --> C --> D --> E --> F --> G\n>                                     |\n>                                  [master]\n>\n> Then you squash (F' is the result of squashing F and G):\n>\n>             [origin/master]\n>                   |\n> A --> B --> C --> D --> E --> F'\n>                               |\n>                            [master]\n>\n> When you want to push now, it's just as if you just created just two\n> commits in the first place, and you can just push normally (assuming no\n> one else has pushed in the mean time.\n\nHmm..You mean, if I do a squash, it will only affects those commits\nthat has been squashed, not any other commits, and their parent-child\nrelations remain the same?\n\nYubin\n\n> The situation is different when you have pushed already:\n>\n>                               [origin/master]\n>                                     |\n> A --> B --> C --> D --> E --> F --> G\n>                                     |\n>                                  [master]\n>\n> Then after you squash, the history would look as follows:\n>\n>                               [origin/master]\n>                                     |\n> A --> B --> C --> D --> E --> F --> G\n>                          \\\n>                           --> F'\n>                               |\n>                            [master]\n>\n> This sitation would look to git like you created F', and someone else\n> had pushed F and G. It will reject the push, saying you would need to\n> merge these changes first (but you don't want this, because you are\n> merging the same changes together).\n>\n> To solve this, you can use git push --force-with-lease=master origin,\n> which will force the push, overwriting the history the remote already\n> had.\n>\n> Hope this helps, Kevin.\n>\n> nb. --force-with-lease is a safer version of just (-f|--force), because\n> it will prevent you from overwriting history you don't have locally, for\n> example when someone else did push already.\n>\n>\n"},{"id":"329305","messageId":"20171001161152.GA1667@alpha.vpn.ikke.info","threadId":"46865","inReplyTo":"CAJYFCiNmDpNNdbRsN-F-mOtcOEVruawEKUtA9h3BAFZZWKStsQ@mail.gmail.com","subject":"Re: will git rebase has side effect","fromName":"Kevin Daudt","fromEmail":"me@ikke.info","sentAt":"2017-10-01T16:11:52Z","receivedAt":"2017-10-01T16:11:58Z","isPatch":false,"sender":{"key":"me@ikke.info","avatar":"https://avatars.githubusercontent.com/u/135698?v=4"},"body":"On Mon, Oct 02, 2017 at 12:06:38AM +0800, Yubin Ruan wrote:\n> 2017-10-01 22:17 GMT+08:00 Kevin Daudt <me@ikke.info>:\n> > Forgot to cc the mailing list.\n> >\n> > On Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:\n> >> Suppose that I have such a history of commit locally:\n> >>\n> >> A --> B --> C --> D\n> >>\n> >> If I then add a few more commits locally\n> >>\n> >> A --> B --> C --> D --> E --> F --> G\n> >>\n> >> And then I do a rebase and squash F and G into one single commit H.\n> >> What side effect will this rebase have? How will this affect \"git push\n> >> origin master\"?\n> >>\n> >> Yubin\n> >\n> > Hello Yubin,\n> >\n> > So the situation is this:\n> >\n> >             [origin/master]\n> >                   |\n> > A --> B --> C --> D --> E --> F --> G\n> >                                     |\n> >                                  [master]\n> >\n> > Then you squash (F' is the result of squashing F and G):\n> >\n> >             [origin/master]\n> >                   |\n> > A --> B --> C --> D --> E --> F'\n> >                               |\n> >                            [master]\n> >\n> > When you want to push now, it's just as if you just created just two\n> > commits in the first place, and you can just push normally (assuming no\n> > one else has pushed in the mean time.\n> \n> Hmm..You mean, if I do a squash, it will only affects those commits\n> that has been squashed, not any other commits, and their parent-child\n> relations remain the same?\n> \n> Yubin\n\nOnly the commits being squashed, and the commits after it (not\napplicable in your case). But not commits that come before the squash.\nRemember that in git, commits point at their parent(s), not the opposite\nway. So if you change commits, only the children will have to change (to\npoint to the new hashes), but not their parents.\n"}]}