Mercurial - active changeset after a pull - mercurial

When you do an hg pull which results in multiple heads, which of the heads is 'active' on your file system?
Ie: Given a local repostory with changesets:
A1 - A2 - A3
And then doing an hg pull which results in multiple heads:
A1 - A2 - A3
\
B3
Prior to doing an hg merge, which changeset will be active on the file system? Will it be A3 or B3?

Not sure what you mean by "active on the filesystem", but after doing hg pull the working directory is not changed. You need to do hg update to update the working folder to one of the pulled commits.
When doing hg update you can specify the changeset you need. If you don't, the working directory is updated to the tip of the current named branch.

Related

Mercurial: Move a modified file between commits

Let's say I have the following commit history:
A - newest
B
C - oldest
I have changed a file foo in B, but I want to move the change from B to A.
How can I do that with hg?
There are several different ways that I can think of. Both have some moderate user requirements (please make sure you have backed up or pushed to a non-publishing repository first).
1 ) Use histedit and amend (requires that each extensions be enabled).
- copy file you wish to move to a safe location
- run hg histedit and edit changeset b and restore file to its original state
- run hg histedit --continue to commit changes.
- copy file from safe location to repository
- run hg amend to append file to changeset A
2 ) Use split and histedit.
- run hg split -r b
- split out all but the file you wish to move into a new changeset
- create a new changeset onto of that containing the fie (give it a temporary description)
- run hg histedit
- move the temp change above A
- roll the temp change into A
3 ) Use hg-evolve uncommit / amend. While this is a somewhat advanced method, I much prefer this one myself.
- run hg update B
- run hg uncommit and select the file you wish to move.
- run hg evolve to correct the stack
- run hg update A
Note: if you get a warning about needing to use --clean use hg shelve before
running the update followed by hg unshelve afterwords.
- run hg amend to add file to change A
4 ) Use hg uncommit all contents of changesets A and B and then recommit using hg commit -i to reassemble the changesets with the desired content.
There are likely a number of other ways, but this is what came to me.
Here's a simplistic but functional approach, maybe for people not very experienced with some of the more advanced HG commands:
Make sure your working directory is clean (no changes).
hg update -r C
hg revert -r B
hg commit ... as needed, but leave out the change destined for A. This creates B'.
hg shelve ... store away the uncommitted changes
hg revert -r A
hg unshelve ... restore uncommitted changes, merging them into the workding directory
hg commit ... creates C'.
hg strip -r B ... (optional!)
(where it says -r A that means use the revision # corresponding to A)
Explanation: we just create two (or more) entirely new changesets and then delete the originals (which is optional).
We're using revert basically to mean "copy from some changeset to the working directory" which I find is very handy in many circumstances.
After these operations -- but prior to using strip -- the history would look like:
*
|
A A'
| |
B B'
|/
C
and strip will just delete A, B.

In mercurial how to pull?

I have cloned a branch name abc from bitbucket into my local by following command:
$ hg clone -b abc https://bitbucket.org/asda/da/
Next i have have created a branch name xyz from abc branch and it is my working branch .
$ hg branch <branch name>
Now my question was can i pull changes from remote abc to local xyz directly by following command:
$ hg pull -b abc
$ hg update
I always checkout to abc branch and then pull changes. When i pull changes nothing changes very confused regarding this.After pull it shows total number of files changed .But not able to see changes.
Another question is that if i pull changes on branch abc and when i checkout xyz branch does all the changes get updated in xyz branch automatically?
Please help me out.
Draw a picture of the branches. When you pull new changesets, they are always added to the same branch, and in the same sequence, that they occupied in the upstream repository. In other words when you pull from abc you extend abc. You don't need to switch to abc before you pull, and you don't need to update afterwards.
a--a--a--a--a1--a2
\
x--x--x
(a = branch abc; a1,a2 = new changesets on abc; x = branch xyz)
The new changesets you pulled make no difference to the tip of branch xyz. To benefit from them in your branch, use the command merge.
hg update xyz
hg merge a2
hg commit
Then you'll be at point X', the new tip of xyz.
a--a--a--a---a1---a2
\ \
x--x--x--X'

Diff after committing locally

I just cloned a repo from their remote.
I built the software, changed about 4 files, committed them locally and now want to create a patch that I can show them.
When I run :
hg diff -U8p abc efg pqr > patch_file
I don't see the changes I made. Does hg diff only compare the current files with the last committed files?
How do I get this to work?
To diff the working directory against a particular revision REV, use
hg diff -r REV
To compare two revisions against each other, use
hg diff -r REV1 -r REV2
To figure out which revisions to compare, examine the output of hg log. If you'll be doing this a lot and the base revision is fixed, give it a name (e.g., whatipulled) with
hg tag -r REV whatipulled
You can then specify whatipulled as the revision, instead of a numeric rev id (or a hash).
To export your diffs in a richer format, including commit comments etc., you can also use the following which is designed for this purpose:
hg export -r REV
There's also hg bundle -r REV, which produces a binary file with similar information.
But if you're sending changes back to the parent repo, the best method is to use hg push. It communicates your changesets directly to the parent; you don't even need to know which changesets need pushing. Of course, you must have the right to push to the parent repo.
hg push [ parent_repo_url ]
(If you pulled from it, mercurial should already know the path and you can leave it out).
If the parent repo is on bitbucket and you don't have pu, you can set up your own account on bitbucket, pull/push to that from your local repo, and then issue a "pull request" to the project repo, asking them to pull from you.
All of the above have options to control their behavior, which see.
From hg help diff
If only one revision is specified then that revision is compared to the working directory
In your diff for -r you must to use old tip (latest "not your" changeset) and update to tip (your latest changeset) before diffing.
If some binary data was modified in your changesets, don't forget to use -g option
hg up & hg diff -r <CSET> -g > some.patch
Improved diff for any active changeset and without hand-work for detecting base changeset (for linear history == in single branch)
hg diff -r "parent(min(outgoing()))" -r tip
By default, hg diff compares the currently checked out file with the last commit. You can change this by adding options:
-r REV compares the currently checked out files with a specific revision REV.
-c REV shows the changes made by revision REV
So in your case hg diff -c 123 ... would give you the diff for commit 123.
My guess is that hg outgoing is exactly what you want -- it compares what you've committed locally with what is at the default remote server and shows you a list of those changesets or with -p the commits.
That does, however, shows each changeset separately. If you want to see all the changes combined, you'd have to do hg diff -r HERE -r THERE or since -r HERE is a default, hg diff -r THERE
I see you've asked in a comment "How do I know what THERE is", where THERE is the last changeset remote has, and you can get that answer by doing hg outgoing. If hg outgoing shows it would send changesets 66, 67, and 68, then you want to do hg diff -r 65 to compare what's already there (65) with what's local (68).

Can mercurial rebase delete a branch?

This is the summary of a hg session:
> hg branch dev
marked working directory as branch dev
(branches are permanent and global, did you want a bookmark?)
> hg branch
dev
> hg ci -m 'test'
> hg update default
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
> hg pull --rebase
pulling from ssh://hg#bitbucket.org/user/repo
searching for changes
adding changesets
adding manifests
adding file changes
added 3 changesets with 44 changes to 44 files (+1 heads)
saved backup bundle to C:\repo\.hg\strip-backup\edc5f75b39d1-backup.hg
The problem is that after all of this, there is no trace whatsoever of the 'dev' branch. I can't make any sense of it. I committed a changeset when in the dev branch so it must have been saved. How is it possible to disappear? Could rebase delete it somehow?
EDIT: just to clarify the 'test' commit is there, but it's in the 'default' branch
Finally able to reproduce it!
Your named branch branches off of a local changeset on the default branch.
When you run pull --rebase it inserts the pulled changesets into the tree and then rebases your local change sets from the default branch onto the pulled default changesets.
Since your branch dev branches off of that local change set, it is rebased as well. Furthermore, since you can't pass --keepbranches to pull --rebase, you lose the branch name.
To prevent that from happening, branch dev off of a public changeset or run rebase manually with --keepbranches.

Mercurial: "undoing" two or more commits

In How do I do a pristine checkout with mercurial? Martin Geisler discuss how to remove already Mercurial commit'ed files using:
hg strip "outgoing()"
But what if I I want to keep my added files which went into "outgoing()" - example:
Two users a and b — starting on the same changeset
User a:
echo "A" > A.txt; hg ci -M -m ""; hg push
User b (forgets to run hg pull -u):
echo "B" > B.txt; hg ci -M -m "" B.txt;
echo "C" > C.txt; hg ci -M -m "" C.txt;
If user b run hg strip "outgoing()" then B.txt and C.txt are lost. hg rollback is not an option since there are two commits.
Can user b revert his files as "locally added - nontracked", then do hg pull -u, which gets A.txt, then handle the add/commit/push for B.txt and C.txt later?
Martin Geisler answered this earlier in the mentioned thread (a comment which I deleted and moved here:
hg update "p1(min(outgoing()))"
hg revert --all --rev tip
hg strip "outgoing()"
hg pull -u
Now user c can finalize his work in the new files B.txt and C.txt and commit+push those.
Other ways to do this?
You could but, by doing so, you are working against one of the biggest features of a DVCS like mercurial, that is, to easily and reliably handle the merging of multiple lines of development as in your case. If user b's goal is to have a line of development with all three changes applied, then the standard way to do that in hg would be to just go ahead and do an hg pull -u which will create a new head containing the change(s) from user a (and any other changes pushed to repo used for pulling) and then use hg merge to merge the two heads, the head containing user b's two change sets and the other containing user a's change set (as pulled). In a simple case like this one with no overlapping changes, hg should do all the right things by default.
$ hg pull -u
[...]
added 1 changesets with 1 changes to 1 files (+1 heads)
not updating: crosses branches (merge branches or update --check to force update)
$ hg merge
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)
$ hg ci -m "merge"
If there were conflicts between the two heads (i.e. both users committed changes to the same files), there might need to be conflict resolution editing as part of the merge; hg will tell you if that is the case.
Another option is the rebase extension. With your scenario:
A and B start with the same history.
A commits and pushs a change.
B commits two changes, but can't push because of A's commit.
B pulls A's change.
B runs hg rebase and pushes.
Before rebase:
Common ---------------------------- A (tip)
\
B1 - B2 (working parent)
After:
Common - A - B1 - B2 (tip, working parent)