When does a new head is created in a repository?

504 Views Asked by At

I'm assuming this is kind of weird question, but I am not sure when exactly a new head is created to a repository, for example in this question :

Explain which line(s) cause the number of heads to change in any of the referenced repositories

1: /home/user> hg clone http://remoteserver/mainrepository clone1

2: /home/user> hg clone http://remoteserver/mainrepository clone2

3: /home/user> cd clone1

4: /home/user/clone1> echo one > a.txt # Create a new file “a.txt” containing “one”

5: /home/user/clone1> echo two > b.txt # Create a new file “b.txt” containing “two”

6: /home/user/clone1> echo three > c.txt # Create a new file “c.txt” containing “three”

7: /home/user/clone1> hg add a.txt b.txt c.txt

8: /home/user/clone1> hg commit -m "Added files"

9: /home/user/clone1> cd ../clone2

10: /home/user/clone2> echo none > a.txt # Create a new file “a.txt” containing “none”

11: /home/user/clone2> echo none > b.txt # Create a new file “b.txt” containing “none”

12: /home/user/clone2> echo none > c.txt # Create a new file “b.txt” containing “none”

13: /home/user/clone2> hg add a.txt

14: /home/user/clone2> hg commit -m "one file"

15: /home/user/clone2> hg add b.txt

16: /home/user/clone2> hg commit -m "another file"

17: /home/user/clone2> hg pull ../clone1

18: /home/user/clone2> hg add c.txt

19: /home/user/clone2> hg commit -m "a third file"

20: /home/user/clone2> hg push -f

21: /home/user/clone2> cd ../clone1

22: /home/user/clone1> hg push -f

23: /home/user/clone1> hg pull

I am not looking for a specific answer to this question, just some keys that will help me understand when does it happen and why.

Thanks in advance !

1

There are 1 best solutions below

0
On BEST ANSWER

A new head can be created in three ways:

  • when you need to use --force on the push command, a new head is created on the repository you push to. Hint: Do never use --force (or its equivalent -f) with push when you do not have to
  • when you commit to a changeset which is not a branch head; thus if you commit to a changeset which has children.
  • when you pull from a repository which adds new changesets on top of a changeset where you locally have already children.

In your case step #22 would introduce a new head to the remote repository. The push --force in step #20 is not helping you to see that it only happens in #22 as you thus systematically mute mercurials hints that a new head is being created.

The number of heads are reduced when you merge different heads (or rebase - but that does not propagate except under certain conditions like non-publishing repository and phase < public).