Search code examples
mercurialdvcsbazaarrebase

Avoid pushing unwanted local history to main repository in Bazaar or Mercurial


I'm new to DVCS so I'm probably misunderstanding some concepts and terminology, but this is the idea of what I'm trying to achieve, and I'm trying to find out if either Bazaar or Mercurial supports this in a straightforward manner:

There is main repository with well-tested code. Say I clone (or pull or branch or whatever the terminology is) from that into a local repository, then every day as I work on the code I commit changes locally, sometimes multiple times a day.

After I'm done with all my changes and testing, I want to get only the latest (locally) committed version of every file put into the main repository, without the dozens of intermediate versions that I committed locally during debugging and unit testing.

From what I've been reading, apparently the entire history of those half-baked versions would get reflected in the main repository if I push to it. Some internet articles seem to suggest that rebase might address that issue if it's handled right, but it's not so clear if/how that can be done, as it seems like rebase is more for avoiding a bifurcated branch/merge history than for avoiding the committing of a large set of intermediate versions.


Solution

  • Some bazaar options.

    1. If you want to get rid of the dozens of local commits, you are actually throwing away history. One way of doing it is with the bzr uncommit command. eg.

      bzr uncommit -rbranch:https://url_to_mainrepo
      

      (Throw away rivisions until you get to the revision of the main repo. Don't worry it will show you what will be done and confirm with you before doing it)

      Then you can do a new commit with all the others collapsed into one.

    2. Bazaar normally hides merged revisions. One way for you to roll up your tiny commits into a merged revision is to keep a local branch/checkout of the main repo. Then when you are ready, bzr merge in your changes into your local main-repo-clone and then commit a merged revision.

      This way you still keep all your history but all the little revisions are neatly rolled up into a merge revision. You can then still see that history when you want.

    Here is examples of how to not see merged revisions:

    $ bzr log
    ------------------------------------------------------------
    revno: 2 [merge]
    message:
      summary of the things I did
    ------------------------------------------------------------
    revno: 1
    message:
      some change on the mainline
    ------------------------------------------------------------
    Use --include-merged or -n0 to see merged revisions.
    

    Here is examples of how to see merged revisions:

    $ bzr log -n0
    ------------------------------------------------------------
    revno: 2 [merge]
    message:
      summary of the things I did
        ------------------------------------------------------------
        revno: 1.1.2
        message:
          my first step
        ------------------------------------------------------------
        revno: 1.1.1
        message:
          my second step
    ------------------------------------------------------------
    revno: 1
    message:
      some change on the mainline