Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial Bookmarks and 'Git like branching'

I am not having any luck using Bookmarks in Mercurial for Git like branching.

From the article: https://www.mercurial-scm.org/wiki/BookmarksExtension, I've set "track.current" to true in my .hgrc file.

Excerpt below:

By default, when several bookmarks point to the same changeset, they will all move forward together. It is possible to obtain a more Git-like experience by adding the following configuration option to your .hgrc

[bookmarks]
track.current = True

However, as soon as I start trying to do parallel / independent development on more than one bookmark, then switch back and forth between the bookmarks, I run into the following:

abort: crosses branches (use 'hg merge' or 'hg update -C')

Example to reproduce:

# Make a new directory and Mercurial repository
$ mkdir bookmark
$ cd bookmark
$ hg init

# Create two bookmarks
$ hg bookmark bk1
$ hg bookmark bk2

# Checkout bk1
$ hg update bk1
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

# Create and commit a file to bk1
$ touch bk1.txt
$ hg add
adding bk1.txt
$ hg commit -m "bk1 file"

# Checkout bk2
$ hg update bk2
0 files updated, 0 files merged, 1 files removed, 0 files unresolved

# Create and commit a file to bk2
$ touch bk2.txt
$ hg add
adding bk2.txt
$ hg commit -m "bk2 file"
created new head

# Checkout bk1
$ hg up bk1
abort: crosses branches (use 'hg merge' or 'hg update -C')

Is this normal behavior, for there to be "crosses branches" forcing a merge or file overwrite, when moving between bookmarks?

For a 'Git-like experience' I would expect to be able to flick back and forth between bk1 and bk2, committing and developing on either, merging if and when I needed to.

like image 779
Ian Hill Avatar asked Nov 22 '09 12:11

Ian Hill


2 Answers

Please upgrade to Mercurial 1.4, which was released last week. Then you will be able to switch between heads on a branch without warning.

like image 50
Martin Geisler Avatar answered Oct 13 '22 00:10

Martin Geisler


Using a Mercurial version earlier than 1.4, you can just provide the -c flag, as long as your working tree is clean (no uncommitted changes).

like image 38
Carl Meyer Avatar answered Oct 12 '22 23:10

Carl Meyer