use hg to synchronize my project between my two computer - mercurial

I have two computer : the desktop in my company and the portable computer in my home.
Now I want to use the hg to synchronize the project between them using a "USB removable disk".
So I wonder how to implement it?
THe pro in my desktop is : D:\work\mypro.
I use the following command to init it:
hg init
Then I connect to the USB disk whose volume label is "H",and get a clone using:
cd H:
hg init
hg clone D:\work\mypro mypro-usb
ANd in my portable computer I use:
cd D:
hg clone H:\mypro-usb mypro-home
However I do not know how to do if I modify some files(remove or add and modify) in the mypro-home,how to make the mypro-usb changed synchronizely,also I want the mypro in my desktop synchronizely.
How to do it?
---------------The following is added after I get an answer from richj----------------
to richj:
Thanks for your reply.
The following is my practice: Pro-Com is the project(initialized as a repository) in my desktop, Pro-USB is the repository in my USB, the Pro-Home is the repository in my home computer.
When I make some change in the Pro-Com, I use the following command:
hg add
hg push Pro-USB
Then I change the directory to Pro-USB,using:
hg update
hg push Pro-Home
In my home computer I run:
hg update
(make some edition)
hg commit
hg push Pro-USB
Then the repository in the USB is the same as that of my home computer,I can push it to my desktop.
In my opinion,operation between repository can be done just by "hg push" and "hg pull",the other commands like "hg update" "hg import" just work between a working-copy and its repository.
Is my understanding right?

To push changes from your working repositories back to your USB drive:
hg push
To get the latest changes from your USB drive:
hg pull
hg update
These two commands can be combined together like this:
hg pull -u
If you want to see which change sets are available to be pushed or pulled use:
hg outgoing
hg incoming
respectively. Any changes that you make to your local file system must be committed to the repository using:
hg commit
before they can be pushed or pulled.

Related

Purging old directories and files from a remote hg repo

I initially committed my project to a hg repo with the following structure:
myapp/
fizz/
buzz.txt
foobar.cfg
whistlefeather/
vroom-vroom-party-starter.xml
I did so using the following commands:
hg add
hg commit -m "Initial commit."
hg push
I then changed my directory structure locally to look like this:
myapp/
buzz/
fizz.txt
config.foobar
whistlefeather/
vroom-vroom-party-starter.xml
I then ran the same following commands:
hg add
hg commit -m "Changing some things."
hg push
When I go to the remote repo, I see it has the following structure (?!?):
myapp/
fizz/
buzz.txt
buzz/
fizz.txt
foobar.cfg
config.foobar
whistlefeather/
vroom-vroom-party-starter.xml
What commands can I run to push/purge the old directories/files from the remote repo (and so that it reflect the directory struture on my local machine)?
The hg add command you issued prior to your second commit did not actually remove files from under version control, but only added new ones. Now your repository is actually a melange of old and new files.
To add new files and remove missing ones, use hg addremove command or hg commit -A
It's actually simple to remember:
hg add adds files to the repo
hg remove removes files
hg move moves or renames files
hg addremove looks at current working dir and adds and removes files from the repo such that only the files still being present will continue to be tracked.
Each of these operation can be done in any sequence. And only a commit will actually create a changeset

how update source on standalone computer with hg?

I use mercurial on a standalone computer. I have also made some small changes of the source code on this computer. Now I want to update this code with a new version that I can bring to this computer on a CD or usb-stick as a gziped tar file. How do I do this update in the best way, and keep my changes of the standalone source.
Update: I forgot to mention that the files on the USB-stick is not from a mercurial database, they are just a bunch of source-files from a perforce controlled source tree. We have mercurial only on the standalone computer.
On the remote machine (first time):
hg clone {path_to_repository} {path_on_usb_stick}
On subsequent runs:
cd {path_to_repository}
hg push {path_on_usb_stick}
Then on the local machine:
cd {path_to_repository}
hg commit
hg pull {path_on_usb_stick}
hg up
At some point, hg might warn you about multiple heads, which means there are conflicts that you need to resolve by running hg merge.
To get your changes from the local machine to the repo server, you reverse the procedure.
Why not just put Mercurial binaries and a .hg repo right on the flash drive. Then you can push/pull to/from it at home, and copy atop it at work.

Mercurial Newbie confused

I am familiar with TFS and Vault, but having just started using Mercurial I seem to be getting into a bit of a mess.
Heres what I (think) I've done:
-Created a central repository on bitbucket.org
-On my desktop PC, cloned repository from bitbucket, added files, commit them, push them to bitbucket
-On my laptop, cloned repository from bitbucket, pulled files, added more files, commit them, push them to bitbucket
I've continued to add, edit etc on the different computers.
Now I've noticed that some files from each computer are not in the bitbucket repository, and therefore only in the local repository. No amount of pulling and pushing seems to get it into the bitbucket repository.
What is the most likely thing I've done wrong?
Is there a way to 'force' by changes up to the bitbucket repository?
Did they get into your local repository? I suspect not, i.e. they were new files that were not added to the commit. Use hg add to add them to the changeset before committing or whatever the equivalent is for whatever mercurial interface you're using.
Edit:
Here's the help from Mercurial:
C:\Users\Bert>hg add --help
hg add [OPTION]... [FILE]...
add the specified files on the next commit
Schedule files to be version controlled and added to the repository.
The files will be added to the repository at the next commit. To undo an
add before that, see "hg forget".
If no names are given, add all files to the repository.
...
See Mercurial: The Definitive Guide (a.k.a. the hg "red book") for more info:
http://hgbook.red-bean.com/read/mercurial-in-daily-use.html
Telling Mercurial which files to track
Mercurial does not work with files in your repository unless you tell it to manage them. The hg status command will tell you which files Mercurial doesn't know about; it uses a “?” to display such files.
To tell Mercurial to track a file, use the hg add command. Once you have added a file, the entry in the output of hg status for that file changes from “?” to “A”.
$ hg init add-example
$ cd add-example
$ echo a > myfile.txt
$ hg status
? myfile.txt
$ hg add myfile.txt
$ hg status
A myfile.txt
$ hg commit -m 'Added one file'
$ hg status
use "hg -v help add" to show global options

No changes are pushed when using hg-git

I'm trying to get the hg-git extension working under Windows and after hours of fiddling, I finally seem to have it working. However, nothing shows up in my git repository even though the output of hg push reads:
importing Hg objects into Git
creating and sending data
github::refs/heads/master => GIT:8d946209
[command completed successfully Wed Oct 20 15:26:47 2010]
Try issuing the command hg bookmark -f master
(use -f to force an existing bookmark to move)
Then try pushing again.
This works because Hg-Git pushes your bookmarks up to the Git server as branches and will pull Git branches down and set them up as bookmarks. (from the official README.md)
And it seems that just after I asked this, I made a trivial change. This was picked up and pushed. So it seems that you have to wait until you've made a new commit in order for hg-git to pick it up.
I had chosen to 'Initialize this repository with a README'. This meant I ended up with two heads, which I couldn't hg merge because one had a bookmark.
To get pushing working, I had to:
configure hg-git and github remote as per https://blog.glyphobet.net/essay/2029
pull from github and update
force the merge (checking which id to use with hg heads),
commit the merge
add a trivial change to a file (add a space char to the end),
commit, then
move the bookmark to the tip
push to my configured github remote
This ended up with commands as follows (substituting in <x> sections)
hg pull github
hg update
hg merge <revision-id-of-incoming-git-version>
hg addremove
hg commit -m 'merged with github'
# make some trivial change to a file - eg add a space where it doesn't cause harm
hg add <changed-file>
hg commit -m 'trivial change'
hg bookmark -f master
hg push github
make sure you pick the remote revision for the merge above - if you don't it doesn't work!

Using Mercurial, how to see History and Log on other Repos

Let's say the repo I have on my notebook's hard drive is cloned from a remote Repo2 initially, the "all serious" Repo, and then we use Repo1 for tmp storage and code sharing.
So now, what if I do a
hg in ssh://someuser#dev.example.com//code/repo1
and then also on repo2, and see some new changesets on both repos, how do I look at what Peter changed for the 3 files he committed and pushed on Repo1?
And how to do it for Repo2? (on Mac and PC)
What about just looking at the log history?
Is it better that Repo1 and Repo2 both run a process "hg serve" at port 8000 and 8001 for other people to look at history using a web browser?
What if there are no such processes running, then the only way is to ssh to that host and cd to the directory and do hg log and hg diff?
Yes, you must have the repository on your local machine to be able to do hg log and all other commands. Mercurial is a distributed revision control system, and so you are expected to make a local clone before you work with a repository.
Setting up hg serve is a good alternative for when you need to quickly look at the history without cloning it first. But for command line operations, you should make a clone.