4

I'm following this post Codeplex: Updating a Fork with Changes from the Master Repository but it seems like it doesn't work for me. As I'm new to Mercurial, I might be missing something..

Scenario

Here is the URLs of the main repository and my fork. I created a fork from main repository a few months back.

Problem

I can't update my fork with the changes from master repository.

Steps taken

Here is the steps that I tried to do but it didn't work.

PS C:\michael sync\git\nuget> hg clone https://hg.codeplex.com/forks/michaelsync/msyncwillmakeyoubetter
destination directory: msyncwillmakeyoubetter
requesting all changes
adding changesets
adding manifests
adding file changes
added 2231 changesets with 13584 changes to 3800 files
updating to branch default
1205 files updated, 0 files merged, 0 files removed, 0 files unresolved

PS C:\michael sync\git\nuget> cd .\msyncwillmakeyoubetter

PS C:\michael sync\git\nuget\msyncwillmakeyoubetter> hg pull https://hg.codeplex.com/nuget
pulling from https://hg.codeplex.com/nuget
searching for changes
adding changesets
adding manifests
adding file changes
added 301 changesets with 2574 changes to 838 files (+1 heads)
(run 'hg heads' to see heads)

PS C:\michael sync\git\nuget\msyncwillmakeyoubetter> hg commit -m "sync the changes from main respo to my fork"
nothing changed

PS C:\michael sync\git\nuget\msyncwillmakeyoubetter> hg push
pushing to https://hg.codeplex.com/forks/michaelsync/msyncwillmakeyoubetter
searching for changes
abort: push creates new remote branches: 1.6, 1.6.1, 1.7!
(use 'hg push --new-branch' to create new remote branches)

What I don't understand is that how come there is no change after pulling the code from master repository. It said nothing changed when I tried to commit.

I checked these posts How can I get the changes from a "master" repository in mercurial for a project hosted on google code? and Mercurial - how to fetch latest changes from parent of fork? but couldn't make it work until now.

Community
  • 1
  • 1
Michael Sync
  • 4,834
  • 10
  • 40
  • 58

1 Answers1

8

First of all, it is really important to understand what exactly the various commands you used do :

  1. pull : retrieve the changes from a repository, but don't apply them to the working copy
  2. commit : apply the changes on the working copy to the local directory
  3. push : push all change sets in the local repository to the remote one
  4. update (which you didn't use) : update your working copy to a specific changeset from the local repository

You'll notice that I use two different terms, working copy and repository.

The repository is all the change sets available, with the various branches, heads, etc.

The working copy is the files you actually see in your file explorer, they can be to totally different state than the last changeset in the repository.

So, once you did your pull, if you want to "apply" the changes to your working copy, you must do an update, Alternatively, you can also du hg pull -u. If you made some changes since the last pull, you may have to merge instead of updating, if you look at the documentation you've linked, they're doing a merge (step 3).

If the update was successful, no need to do a commit, the changes are already in your local repository. If you had to do a merge, a commit will be necessary to acknowledge the changes you made.

Concerning the push part, you're creating new branches by doing so like stated by the error message. By default, Mercurial don't push changesets creating new branches, you must use the stated command : hg push --new-branch or push a branch specifically hg push mybranch

I hope my explanations are clear enough, otherwise feel free to comment. I also recommend you read some tutorial about Mercurial, for example this one : http://hginit.com/

krtek
  • 26,334
  • 5
  • 56
  • 84
  • Thanks for explanation. I would say that I have two repositories 1) main and 2) my fork.. I have a working copy. My working copy is a clone of my fork. and as you can see, I didn't make any change. This is the first time that I'm cloning my fork in my new machine so I don't think I need to use "hg update".. In the doc that I linked, it said that I need to use "hg merge" if there is any change in my working copy. But in my case, I don't have any change. – Michael Sync Mar 12 '12 at 06:41
  • I think you are covering the scenario where I have one working copy and one repository. But I'm trying to sync two repositories via my working copy. – Michael Sync Mar 12 '12 at 06:47
  • Please feel free to let me know if I misunderstand your answer.. Or, Feel free to let me know if I missed something in my steps. – Michael Sync Mar 12 '12 at 06:48
  • 1
    You're missunderstanding the difference between "working copy" and "repository", each of **your clone as both of them**, it's the main principle of a DVCS. The number of **remote repository** doesn't change a thing to the answer. It's totally normal that `commit` says there's no change, because there isn't. `commit` works on a **local level** where `pull`/`push` works on a **remote level**. Concerning your `push` problems, just run the commande proposed by Mercurial : `hg push --new-branches`. And BTW, you should really read and follow the tutorial I linked to understand all these differences – krtek Mar 12 '12 at 07:07
  • 1
    This answer has something wrong. You do not need to commit after update *unless you already had changes in your working folder*. The reason the problem in the question crops up is that there are new branches in the repository after the pull, compared to the server copy of the fork. – Lasse V. Karlsen Mar 12 '12 at 09:45
  • @LasseV.Karlsen Like I said in my answer : "If the update was successful, no need to do a commit". I precise that the commit is needed only in case of a merge, but maybe my answer isn't clear enough, feel free to correct the wording, english isn't my mother tongue at all ;) – krtek Mar 12 '12 at 09:59
  • Thanks! That explain why I got "new branch" prob. I've been using git for one year so I do have very basic understanding about how pull and push works. (but I'm very very basic user and HgInit link definitely help me.) When I do hg pull from master to my local, new files are added to my local which is a clone of my fork. So, I thought when I commit my local, the changes that I pull from master should be committed to my fork. but i was wrong.. – Michael Sync Mar 12 '12 at 10:30