37

Can someone clarify what's the exact difference between update and pull commands?

Thanks.

emurad
  • 3,448
  • 10
  • 40
  • 47
  • 11
    If this is confusing, you might want to read a [Mercurial Tutorial](http://hginit.com) – Joel Spolsky Dec 09 '10 at 02:36
  • 1
    The fetch extension is also worth looking at since it combines a pull, merge and commit (if necessary) as well as update into a single command. – Binary Phile Dec 09 '10 at 05:23

4 Answers4

50

hg update : http://www.selenic.com/mercurial/hg.1.html#update

  • Update the repository's working directory (the "working copy") to the specified revision of the repository

hg pull : http://www.selenic.com/mercurial/hg.1.html#pull

  • Allows you to bring changes from a remote repository

So when you do an hg pull, you bring changes to your repository which is under .hg. It will not reflect in your working directory.

After that, when you do a hg update, the changes are brought to your working copy.

Your repo                                 Remote Repo
 \                                        \
  |                hg pull                 |
  |-.hg  <-------------------------------- |-.hg
  |   |  --------------------------------> |
  |  hg update       hg push               |
  |   |                                    |
  |- working folder                        |- working folder

This is very usual confusion when coming from subversion like version control systems.

In subversion : svn update bring the changes from central repo server to your working copy

But in DVCSs , you have both a local repository and working copy. So update does exactly the same but pulls the changes from your local repo to local working copy.

2Toad
  • 14,799
  • 7
  • 42
  • 42
pyfunc
  • 65,343
  • 15
  • 148
  • 136
18

Mercurial is a distributed revision control system, so you have the whole repo history as well as your version of the code (called the "working copy").

pull brings in remote changes to your local repo.

update changes your working copy to match the newest version in your local repo.

So if you clone a remote branch and keep running update, your code won't change because you're never downloading remote code. If you keep running pull, then your code won't change because you're never using the remote code (applying it to your working version of the code).

idbrii
  • 10,975
  • 5
  • 66
  • 107
6

The pull command pulls changes from the parent repository but does not actually make any changes to the files in the repository.

Update command is used to actually update the files in the repository.

Refer: https://developer.mozilla.org/en-US/docs/Mercurial_FAQ#What%27s_the_difference_between_hg_pull_and_hg_update.3F

thiru_k
  • 847
  • 2
  • 12
  • 21
4

This picture from this link can help to understand it:

How Mercurial does it

colidyre
  • 4,170
  • 12
  • 37
  • 53