From: Nico Williams <nico@cryptonector.com>
To: Mike Stump <mikestump@comcast.net>
Cc: "Sam Vilain" <sam@vilain.net>,
"Jakub Narębski" <jnareb@gmail.com>,
"brian m. carlson" <sandals@crustytoothpaste.net>,
"git discussion list" <git@vger.kernel.org>
Subject: Rebase safely (Re: cherry picking and merge)
Date: Wed, 6 Aug 2014 14:44:59 -0500 [thread overview]
Message-ID: <20140806194457.GD23449@localhost> (raw)
In-Reply-To: <96B703A6-58B0-458A-8A2D-699EA8F1941B@comcast.net>
On Wed, Aug 06, 2014 at 12:11:16PM -0700, Mike Stump wrote:
> On Aug 1, 2014, at 4:40 PM, Nico Williams <nico@cryptonector.com> wrote:
> > As for rebase, I still don't understand why it doesn't work for you.
>
> http://git-scm.com/docs/git-rebase says:
>
> Rebasing (or any other form of rewriting) a branch that others have
> based work on is a bad idea
>
> If you read stack-overflow, you will discover a ton of people that
> like doing this, and they get hammered because of it. My use case
> fits exactly (as near as I can tell) the hammer case.
It's not a good idea to rebase a branch in a repo that others pull from.
There's nothing wrong with rebasing your patches on that same branch in
your clone as long as the end result is a fast forward merge when you
push.
$ git clone https://..../blah
$ cd blah
$ <do some work>
$ git commit ...
$ git fetch origin
--->$ git rebase origin/master
$ git push origin master
There's NOTHING wrong with that rebase. It's perfectly safe because
it's only in your *private* clone.
(If later you publish that clone and expect people to track your master
branch, then rebase becomes problematic, but that's not something most
people ever do with their clones.)
The only use-case I've seen where a rebase-based workflow doesn't work
is where you have multiple upstreams that you're following. I.e., the
upstream forked and you want to take some commits from one, some from
the other, or otherwise keep a merge of both.
(Also, if an upstream is ever rebased you can usually recover on the
downstream side by rebasing with the --onto option, so it's not the end
of the world.)
> Now, I found the stack-overflow commentary first, and all the horrors
> of it, and all the nuances. I carefully read what people were doing,
> how what I wanted to related to what they were doing, and it sure felt
> like I was in the, don’t go there camp.
A lot of people rant about rebase. They're wrong. They've distorted
your perspective.
> So, I like to know if I’m driving off a cliff, before I do. I’m the
> [...]
There's just two simple rules to follow and you'll be safe:
1) NEVER git push -f (--force) to a "published" repo/branch.
The upstream should enforce this with a receive hook.
2) NEVER work directly in a published repo. Instead work in a private
clone. To help make sure of this, never publish a non-bare repo
(bare == has no workspace; non-bare == has a workspace).
If you ever do a rebase that produces results you're unhappy with you
can undo that rebase like so:
- use git reflog to find the branch's previous HEAD commit
- reset the branch to point to that commit
It really helps to think of git as a pile of commits arranged in a
Merkle has tree. Branches and tags are just symbolic names for specific
commits. Rebase builds a new line of commits in the tree then it
changes the symbolic branch name's HEAD to point to the head of that new
line of commits, BUT NOTHING IS LOST in the pile of commits that is the
repo, not until you git-prune(1) to remove commits not reachable from
symbolic names (branches and tags).
> > The only case where I can imagine not using a
> > rebase-heavy workflow is where I have to track multiple forked
> > upstreams and so I want to merge each into my branch.
>
> So, sounds like I fit that use case and rebase could be my friend.
Excellent.
> How do I square what you said and:
>
> Rebasing (or any other form of rewriting) a branch that others have
> based work on is a bad idea
>
> ?
See above.
> I want all old refs in old emails to work. I want all refs in
They will if you stick to the two rules I mention above.
> bugzilla to work. I want to see the original dates of all the work.
Ditto.
> I want git blame to report those artifacts in email and bugzilla. I
> have coworkers that I push to, pull from (through a single sharing
> point, we call the master tree). We work on gcc, we pull git gcc down
> to a local copy, then merge it into our tree. I want to cherry pick
> changes from upstream. I do work and push to our master, I pull work
> of coworkers from the master, my coworkers do the same. Isn’t this
> the canonical open source use case?
That means that you have/maintain an intermediate upstream, yes?
This is a bit trickier since once in a while that intermediate upstream
and everyone downstream of it has to catch up with the real upstream.
Here you have two options:
- the intermediate diverges from the real upstream, and then you
merge/cherry-pick from the upstream as needed
The intermediate's maintainer must still merge/rebase/cherry-pick
from the intermediate branch and onto a branch of the upstream in
order to push to the upstream.
or
- the intermediate occasionally rebases onto the upstream, and then the
repos downstream of the intermediate must also rebase with --onto.
In this case the intermediate's maintainer must tell the downstreams
what rebase command to execute.
This makes it easier to push from the intermediate to the upstream:
the intermediate's commits should always be on top of the upstream
(at rebase time) so it's easy to push them.
The latter is the workflow we used at Sun for decades for large
projects. We followed that workflow long before git, first with
Teamware, then later with Mercurial (even though Mercurial technically
had no support for rebasing at that time; we just made it work).
(We always left symbolic names for the pre-rebase branch HEADs, mind
you, to make life easier for everyone.)
> > (I find that many users are allergic to rebasing. Many people have
> > told me that rebase is lying, that history must be immutable, and so
> > on, all ignoring that: git users don't rebase published branches,
>
> So, when I push, and someone else pulls, is that published? I thought
> it was.
Yes. You shouldn't push -f. As long as you don't there's no problem.
Nico
--
next prev parent reply other threads:[~2014-08-06 19:45 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-01 0:58 cherry picking and merge Mike Stump
2014-08-01 2:43 ` brian m. carlson
2014-08-01 16:27 ` Jakub Narębski
2014-08-01 17:48 ` Mike Stump
2014-08-01 18:57 ` Philip Oakley
2014-08-01 22:10 ` Mike Stump
2014-08-02 10:39 ` Philip Oakley
2014-08-02 16:29 ` Philip Oakley
[not found] ` <CANQwDwc4YPdK+a0Oc-jWPTRyM5GiP-CMuRY1inxJY41GwUGBvQ@mail.gmail.com>
2014-08-01 19:01 ` Fwd: " Jakub Narębski
2014-08-01 22:24 ` Mike Stump
2014-08-02 11:44 ` Philip Oakley
2014-08-06 15:43 ` Jakub Narębski
2014-08-06 18:41 ` Mike Stump
2014-08-01 20:12 ` Sam Vilain
2014-08-01 23:06 ` Mike Stump
2014-08-01 23:40 ` Nico Williams
2014-08-02 0:18 ` Alex Davidson
2014-08-06 19:11 ` Mike Stump
2014-08-06 19:44 ` Nico Williams [this message]
2014-08-06 20:13 ` Rebase safely (Re: cherry picking and merge) Nico Williams
[not found] ` <A769B84E-42D1-44AC-B0A8-0F4E68AB71FB@comcast.net>
2014-08-07 5:11 ` Nico Williams
2014-08-08 17:34 ` Mike Stump
2014-08-08 18:27 ` Nico Williams
2014-08-08 16:23 ` Fwd: " Mike Stump
2014-08-01 16:56 ` cherry picking and merge Mike Stump
2014-08-21 17:36 ` Keller, Jacob E
2014-08-21 17:58 ` Keller, Jacob E
2014-08-01 19:22 ` Nico Williams
2014-08-01 22:13 ` Mike Stump
2014-08-01 22:19 ` Nico Williams
2014-08-01 20:02 ` Jonathan Nieder
2014-08-01 20:50 ` Jonathan Nieder
2014-08-01 20:55 ` Nico Williams
2014-08-01 21:44 ` Junio C Hamano
2014-08-01 22:00 ` Nico Williams
2014-08-01 22:09 ` Junio C Hamano
2014-08-06 15:58 ` Jakub Narębski
2014-08-06 16:26 ` Nico Williams
2014-08-06 23:16 ` Junio C Hamano
2014-08-06 23:20 ` Junio C Hamano
2014-08-01 23:47 ` Mike Stump
2014-08-01 22:35 ` Mike Stump
2014-08-01 22:42 ` Jonathan Nieder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140806194457.GD23449@localhost \
--to=nico@cryptonector.com \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
--cc=mikestump@comcast.net \
--cc=sam@vilain.net \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).