* will git rebase has side effect
@ 2017-10-01 13:23 Yubin Ruan
[not found] ` <20171001134155.GA20406@alpha.vpn.ikke.info>
0 siblings, 1 reply; 4+ messages in thread
From: Yubin Ruan @ 2017-10-01 13:23 UTC (permalink / raw)
To: git
Suppose that I have such a history of commit locally:
A --> B --> C --> D
If I then add a few more commits locally
A --> B --> C --> D --> E --> F --> G
And then I do a rebase and squash F and G into one single commit H.
What side effect will this rebase have? How will this affect "git push
origin master"?
Yubin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: will git rebase has side effect
[not found] ` <20171001134155.GA20406@alpha.vpn.ikke.info>
@ 2017-10-01 14:17 ` Kevin Daudt
2017-10-01 16:06 ` Yubin Ruan
0 siblings, 1 reply; 4+ messages in thread
From: Kevin Daudt @ 2017-10-01 14:17 UTC (permalink / raw)
To: Yubin Ruan; +Cc: git
Forgot to cc the mailing list.
On Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:
> Suppose that I have such a history of commit locally:
>
> A --> B --> C --> D
>
> If I then add a few more commits locally
>
> A --> B --> C --> D --> E --> F --> G
>
> And then I do a rebase and squash F and G into one single commit H.
> What side effect will this rebase have? How will this affect "git push
> origin master"?
>
> Yubin
Hello Yubin,
So the situation is this:
[origin/master]
|
A --> B --> C --> D --> E --> F --> G
|
[master]
Then you squash (F' is the result of squashing F and G):
[origin/master]
|
A --> B --> C --> D --> E --> F'
|
[master]
When you want to push now, it's just as if you just created just two
commits in the first place, and you can just push normally (assuming no
one else has pushed in the mean time.
The situation is different when you have pushed already:
[origin/master]
|
A --> B --> C --> D --> E --> F --> G
|
[master]
Then after you squash, the history would look as follows:
[origin/master]
|
A --> B --> C --> D --> E --> F --> G
\
--> F'
|
[master]
This sitation would look to git like you created F', and someone else
had pushed F and G. It will reject the push, saying you would need to
merge these changes first (but you don't want this, because you are
merging the same changes together).
To solve this, you can use git push --force-with-lease=master origin,
which will force the push, overwriting the history the remote already
had.
Hope this helps, Kevin.
nb. --force-with-lease is a safer version of just (-f|--force), because
it will prevent you from overwriting history you don't have locally, for
example when someone else did push already.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: will git rebase has side effect
2017-10-01 14:17 ` Kevin Daudt
@ 2017-10-01 16:06 ` Yubin Ruan
2017-10-01 16:11 ` Kevin Daudt
0 siblings, 1 reply; 4+ messages in thread
From: Yubin Ruan @ 2017-10-01 16:06 UTC (permalink / raw)
To: Kevin Daudt; +Cc: git
2017-10-01 22:17 GMT+08:00 Kevin Daudt <me@ikke.info>:
> Forgot to cc the mailing list.
>
> On Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:
>> Suppose that I have such a history of commit locally:
>>
>> A --> B --> C --> D
>>
>> If I then add a few more commits locally
>>
>> A --> B --> C --> D --> E --> F --> G
>>
>> And then I do a rebase and squash F and G into one single commit H.
>> What side effect will this rebase have? How will this affect "git push
>> origin master"?
>>
>> Yubin
>
> Hello Yubin,
>
> So the situation is this:
>
> [origin/master]
> |
> A --> B --> C --> D --> E --> F --> G
> |
> [master]
>
> Then you squash (F' is the result of squashing F and G):
>
> [origin/master]
> |
> A --> B --> C --> D --> E --> F'
> |
> [master]
>
> When you want to push now, it's just as if you just created just two
> commits in the first place, and you can just push normally (assuming no
> one else has pushed in the mean time.
Hmm..You mean, if I do a squash, it will only affects those commits
that has been squashed, not any other commits, and their parent-child
relations remain the same?
Yubin
> The situation is different when you have pushed already:
>
> [origin/master]
> |
> A --> B --> C --> D --> E --> F --> G
> |
> [master]
>
> Then after you squash, the history would look as follows:
>
> [origin/master]
> |
> A --> B --> C --> D --> E --> F --> G
> \
> --> F'
> |
> [master]
>
> This sitation would look to git like you created F', and someone else
> had pushed F and G. It will reject the push, saying you would need to
> merge these changes first (but you don't want this, because you are
> merging the same changes together).
>
> To solve this, you can use git push --force-with-lease=master origin,
> which will force the push, overwriting the history the remote already
> had.
>
> Hope this helps, Kevin.
>
> nb. --force-with-lease is a safer version of just (-f|--force), because
> it will prevent you from overwriting history you don't have locally, for
> example when someone else did push already.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: will git rebase has side effect
2017-10-01 16:06 ` Yubin Ruan
@ 2017-10-01 16:11 ` Kevin Daudt
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Daudt @ 2017-10-01 16:11 UTC (permalink / raw)
To: Yubin Ruan; +Cc: git
On Mon, Oct 02, 2017 at 12:06:38AM +0800, Yubin Ruan wrote:
> 2017-10-01 22:17 GMT+08:00 Kevin Daudt <me@ikke.info>:
> > Forgot to cc the mailing list.
> >
> > On Sun, Oct 01, 2017 at 09:23:23PM +0800, Yubin Ruan wrote:
> >> Suppose that I have such a history of commit locally:
> >>
> >> A --> B --> C --> D
> >>
> >> If I then add a few more commits locally
> >>
> >> A --> B --> C --> D --> E --> F --> G
> >>
> >> And then I do a rebase and squash F and G into one single commit H.
> >> What side effect will this rebase have? How will this affect "git push
> >> origin master"?
> >>
> >> Yubin
> >
> > Hello Yubin,
> >
> > So the situation is this:
> >
> > [origin/master]
> > |
> > A --> B --> C --> D --> E --> F --> G
> > |
> > [master]
> >
> > Then you squash (F' is the result of squashing F and G):
> >
> > [origin/master]
> > |
> > A --> B --> C --> D --> E --> F'
> > |
> > [master]
> >
> > When you want to push now, it's just as if you just created just two
> > commits in the first place, and you can just push normally (assuming no
> > one else has pushed in the mean time.
>
> Hmm..You mean, if I do a squash, it will only affects those commits
> that has been squashed, not any other commits, and their parent-child
> relations remain the same?
>
> Yubin
Only the commits being squashed, and the commits after it (not
applicable in your case). But not commits that come before the squash.
Remember that in git, commits point at their parent(s), not the opposite
way. So if you change commits, only the children will have to change (to
point to the new hashes), but not their parents.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-01 16:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-01 13:23 will git rebase has side effect Yubin Ruan
[not found] ` <20171001134155.GA20406@alpha.vpn.ikke.info>
2017-10-01 14:17 ` Kevin Daudt
2017-10-01 16:06 ` Yubin Ruan
2017-10-01 16:11 ` Kevin Daudt
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).