My repo is currently as follows:
O 7: default
|
O 6: default
|
| O 5: default
| |
| O 4: default
| |
| O 3: default
| /
O 2: default
|
O 1: default
I would like to move 6 and 7 to a new branch, how can I do it?
You can use the rebase extension for this. It needs to be enabled but that link has the information on how to do it.
The commands would be:
hg update 2
hg branch newbranch
hg commit -m "Creating new branch"
hg rebase -s 6 -d 8
This creates the new branch, commits it (which would create revision 8 in your example) and then moves revision 6 and its descendants onto the new branch. Obviously, you'd need to look up the actual revision numbers for your repository.
You could also do it with the mq extension but I think that rebase is easier to use in this instance.
Depends how you define the term "branch". If you're talking about named branches then Steve Kaye's answer is fine.
If you're talking about a branch like 5 & 6 are on a branch in your diagram, then you don't need to do anything. 6 & 7 are already on their own branch. You can leave them alone, and move back to revision 2 to continue work there.
hg update 2
<continue work>
hg commit -m "New Stuff"
That will leave you with a graph like this:
o 8: default
|
| O 7: default
| |
| O 6: default
| |
| | O 5: default
| | |
| | O 4: default
| | |
| | O 3: default
\ | /
O 2: default
|
O 1: default
If you want to assign a name to each of those tips, take a look at bookmarks.
hg bookmark -r 8 stable
hg bookmark -r 7 experimental-stuff
hg bookmark -r 5 some-feature
... and then you can change between them by name.
Related
Currently I am struggling with the Mercurial (v. 2.6.2) log feature. For creation of a change log of our software I have to collect the following set of changeset:
|
O A First interested revision on default
|
O B start of branch
|\
| \
| O C Commit on branch
O | D commit on default
| /
|/
O E Merge from branch to default
|
|
O F start of release branch
|\
| \
O | G on-going development on default
| O H Patch fix on release branch
| |
So what I try to get is a collection of changeset that contain A,(B),(C),D,E,(F),H.
The changesets in brackets would not harm if they are part of the log, but they would not be necessary. The changeset G must not be part of the log.
$ hg help revsets
$ hg log -r A::H
I have 2 repositories A and B. I make 5 changes to A, but only 2 of them should also appear in B. So this is what I tried:
Pushed the 5 changes to repo A
Changed the path of repo B to that of repo A
Clicked the "Check for incoming changesets" button for repo B
Now I see the 5 changes I made for repo A. This is where I am stuck, how can I only get 2 of the 5 changesets now? I tried "Pull to here", but this does not work in my case, it gets all changesets below the one I selected.
How can I get for example the first and third changeset from the list? Possible at all?
Thanks! :)
When you pull changesets between repositories you cannot skip changesets in between. If a changeset has different parents in two repositories, it is not the same changeset.
You can accomplish what you are after by exporting patches of the changesets you want and then import them into the other repository. That way, you have the changes you want from repo A in B, but the changesets will not have the same nodeid in the two repositories.
It sounds like A and B were clones of the same repository. If that is the case, branching is probably what you need. If you have a history where A contains:
C:\example>hg glog --template "rev{rev}:{desc}\r\n"
# rev6:change7
|
o rev5:change6
|
o rev4:change5
|
o rev3:change4
|
o rev2:change3
|
o rev1:change2
|
o rev0:change1
If your B was originally just rev0 and rev1 and you wanted rev3 and rev5 added to it, you can just update to rev1 and graft rev3 and rev5 onto it:
C:\example>hg update 1
0 files updated, 0 files merged, 5 files removed, 0 files unresolved
C:\example>hg glog --template "rev{rev}:{desc}\r\n"
o rev6:change7
|
o rev5:change6
|
o rev4:change5
|
o rev3:change4
|
o rev2:change3
|
# rev1:change2
|
o rev0:change1
C:\example>hg graft 3 5
grafting revision 3
grafting revision 5
C:\example>hg glog --template "rev{rev}:{desc}\r\n"
# rev8:change6 <--- contains change 1, 2, 4, 6
|
o rev7:change4
|
| o rev6:change7 <--- contains changes 1-7.
| |
| o rev5:change6
| |
| o rev4:change5
| |
| o rev3:change4
| |
| o rev2:change3
|/
o rev1:change2
|
o rev0:change1
To avoid duplication of changesets and a little pre-planning, the changes that need to be on both A and B branches can be checked into B and merged into A, whereas changesets that only belong on A can be directly checked into A:
C:\example>hg glog --template "rev{rev}:{branch}:{desc}\r\n"
# rev8:A:change7 <--- contains changes 1-7.
|
o rev7:A:Merge
|\
| o rev6:B:change6 <--- contains change 1, 2, 4, 6
| |
o | rev5:A:change5
| |
o | rev4:A:Merge
|\|
| o rev3:B:change4
| |
o | rev2:A:change3
|/
o rev1:default:change2
|
o rev0:default:change1
In know this is a convoluted scenario but this is my situation. We have
files (*.doc) being updated and posted to SharePoint. I want them in Mercurial. We've have a script that exports these files to a windows share that is marked as a mercurial repository (cloned) with the intention of automatically pushing the files into a central mercurial repository.
The initial exportation of the files resulted in these files being marked as unversioned. A simple
hg add
hg push
moved the files into the desired central repo. These files are automatically exported (overwriting the files) nightly to the windows share. But mercurial does not recognize any changes.
hg status
results are empty.
My question is how can I get Mercurial to recognize the changes so they can be pushed?
Thanks
My understanding is that you have two repos, one a clone of the central repo. You have to consider them as separate repository from here on.
hg status only shows the difference between the working copy and pristine files in repo (.hg directory)
Bringing changes to the repo will show up in hg log and not hg status
Here is a normal procedure.
+------+ +------+
|Repo A| |Repo B|
+------+ +------+
New File | |
.............> | |
| hg add |
| hg commit |
Files in repo A | |
--------------- | |
| hg push |
|------------------ | Files in Repo B
| hg pull |
| | hg update
| | hg status (empty)
| | hg log (Will show new
version )
Also are MS word Doc files would be considered as binary files and you may not take great advantage of version control.
Sorry for being a bit pedantic but the difference between repo and working directory causes enough confusion. Files pulled in repo will only show up with hg update:
+------------+ +---------+
|Your working| |Your Repo|
|directory | |.hg dir |
+------------+ +---------+
| |
| hg status |
|-----------------------------|
| shows difference between | hg pull <--
| working dir and repo |-------------
| | <-- hg push
| | from another repo
| |
| hg update | hg pull or push
| <-------------------------- | deals with repo
| This brings latest change | and not working
| version from repo to | dir
working dir
Is it possible to, instead of merging one branch into another existing branch, merge 2 branches into a 3rd new branch?
Just merge your 2 existing branches and consider the merge as the tip of the 3rd new branch and the previous heads of the merged branches as your 1st and 2nd branch:
o changeset: 3:92692c4a6b12
|\ bookmark: masala
| | summary: merge salt and pepper
| |
| o changeset: 2:a5f955adf03d
| | bookmark: pepper
| | summary: add some pepper
| |
o | changeset: 1:2b56f2dc115f
|/ bookmark: salt
| summary: add some salt
|
o changeset: 0:e992ce7dd508
summary: initial
Here bookmarks have been used to mark different lines in development. So if you want to work in the new 3rd branch, update to masala, if you want to work on your 1st branch, update to salt, and similar for the 2nd branch update to pepper before you continue to work and commit.
If you prefer working with named branches (instead of bookmarks), just issue a hg branch masala before you commit the merge of revision 2 and 1.
The basic message is that although the graph only has one head, you are free to interpret it as 3 different lines of development.
Now, let's say you want to continue the work in the 2nd branch, pepper:
$ hg up pepper
... hack ...
$ hg ci -m "need more pepper"
And then you have some ideas for the salt thing:
$ hg up salt
... hack ...
$ hg ci -m "less salt please"
Now the history graph shows your 3 branches more clearly:
o changeset: 5:d1f8eb72119a
| bookmark: salt
| summary: less salt please
|
| o changeset: 4:acc9b01f584f
| | bookmark: pepper
| | summary: need more pepper
| |
+---o changeset: 3:92692c4a6b12
| |/ bookmark: masala
| | summary: merge salt and pepper
| |
| o changeset: 2:a5f955adf03d
| | summary: add some pepper
| |
o | changeset: 1:2b56f2dc115f
|/ summary: add some salt
|
o changeset: 0:e992ce7dd508
summary: initial
An alternative to bookmarks and named branches is to use different clones for individual branches. That is you clone your repo with the unmerged branches and merge them in the clone. Which approach is best, depends on your specific workflow and personal preferences.
I want to be able to get a "hg log" of every changeset that appears in the graph between
changeset1 and changeset2. I cannot find a way to do it without either
a) omitting nodes on named branches that ARE merged between changeset1:changset2
or b) including nodes on named branches that ARE NOT ancestors of changeset2
Here's a "hg glog" of a simple example with 2 named branches plus the default branch. One named branch gets merged and so its nodes are relevant, the other is irrelevant:
# changeset: 5:e384fe418e9b
|\ tag: tip
| | parent: 2:7dc7af503071
| | parent: 3:0a9be59d576e
| | summary: merge somefeature branch into default
| |
| | o changeset: 4:4e8c9ca127c9
| | | branch: unmerged_feature
| | | parent: 1:ef98ad136fa8
| | | summary: change that is not merged into ending changeset
| | |
| o | changeset: 3:0a9be59d576e
| |/ branch: somefeature
| | parent: 1:ef98ad136fa8
| | summary: changed b.txt
| |
o | changeset: 2:7dc7af503071
| summary: changed a.txt
|
o changeset: 1:ef98ad136fa8
| summary: added b.txt
|
o changeset: 0:271b22b4ad30
summary: added a.txt
I want a log command that will give me all the nodes that are descendent of rev 0 and ancestors of rev 5. This is everything except rev 4.
I can get too much info:
hg log -r 0:5 --template "{rev}:branch={branches},desc={desc}\n"
This gives me a log entry for rev 4, which is not an ancestor of rev 5:
0:branch=,desc=added a.txt
1:branch=,desc=added b.txt
2:branch=,desc=changed a.txt
3:branch=somefeature,desc=changed b.txt
4:branch=unmerged_feature,desc=change that is not merged into ending changeset
5:branch=,desc=merge somefeature branch into default
I can get too little info:
hg log -b default -r 0:5 --template "{rev}:branch={branches},desc={desc}\n"
omits rev 3, which is a descendent of rev 0 and ancestor of rev 5
0:branch=,desc=added a.txt
1:branch=,desc=added b.txt
2:branch=,desc=changed a.txt
5:branch=,desc=merge somefeature branch into default
If you're using a newer version of Mercurial (1.6.0 or higher), you can use the revsets feature. In this case, you need the ancestors() operator:
hg log --rev ancestors(5)
See hg help revsets for more information.