Is it possible to move a bookmark from one head to another without committing any file changes? I've tried:
hg update <destination-head>
hg bookmark bookmark-to-move -f
hg commit
But Mercurial complains nothing changed and when I try to hg push -f I get no changes found. Any ideas?
You need to use the -B flag to hg push in order to make it move the bookmark.
If a bookmark is already exported (present in both source and destination), then a simple hg push will move the bookmark forward in the destination. In your case, the local bookmark is not a descendant of the remote bookmark, and so hg push alone will no move it.
Using
hg push -B bookmark-to-move
will work and move the remote bookmark as you want.
you can also run
hg bookmark -r . yourbookmark
hg update yourbookmark
Related
Is there an option for hg pull to force-update (non-forward) all bookmarks or even prune all bookmarks which are not present in the remote repository anymore?
By "pruning" I mean to get rid of local bookmarks which are not present in the remote repository anymore. Otherwise, local bookmarks would constantly accumulate even they are already obsolete.
Put it with other words, I would like to work with bookmarks as I would work with Git (remote) refs.
If there is no built-in way to do this, what is the recommended sequence of commands to perform these tasks?
The question is not entirely clear, so I'm taking a bit of a guess here. Bookmarks will normally be updated during a pull, unless they were changed to point to an earlier revision. In this case, you can use hg pull -B <bookmarkname> to pull a bookmark, anyway.
If by pruning bookmarks you mean deleting them from the remote server, you first have to delete them locally, then push the deleted bookmark. I.e.
hg bookmark -d <bookmarkname>
hg push -B <bookmarkname> <repository>
The easiest way to get rid of all bookmarks that don't exist on the remote repository is to first delete all inactive ones, and then pull from the repository again.
Example:
hg bookmark -d $(hg bookmarks | awk '{if (NF == 2) print $1;}')
hg pull
You can put the first command in your .hgrc file as an alias, e.g.:
[alias]
clrbookmarks = !$HG bookmark -d $($HG bookmarks | awk '{if (NF == 2) print $$1;}')
I have a commit onto which I have amended some files. Some of these files that were part of the amend I do not want in this commit. Is there a way in Mercurial to remove certain files from the commit without losing the changes I have made to them? Thank you.
Steps:
Made some changes
hg commit -m
Made some more changes (some of these file accidentally amended)
hg amend
Try out:
hg forget somefile.txt
hg commit --amend
If the file was new (i.e. you had used hg add).
If that file already existed try:
cp somefile.txt somefile.txt.bak
hg revert somefile.txt --rev .~1
hg commit --amend
Which is basically telling mercurial to revert the file (somefile.txt) back to the state it was one revision ago (--rev .~1).
Just make sure to back up the file you are reverting before entering the command so that you do not lose your changes. I was under the impression mercurial does this automatically for you, but after testing it quickly I'm not so sure.
hg uncommit somefile.txt does exactly this for me.
Like plain git reset, it removes the change from the commit but leaves the file contents unchanged, so now hg diff shows the change you just uncommitted.
The uncommit command claims to come from the uncommit extension, but may actually be coming from the evolve extension, I admit I'm not 100% sure!
I opened a second branch (branch2) locally in hg and pushed it to bitbucket. After that i merged the two branches locally and pushed it again...I have branch2 still living on bitbucket. How do i delete branch2 on bitbucket?
Have you tried closing it? From hg help branch:
Use "hg commit --close-branch" to mark this branch as closed.
Closing doesn't exactly delete a branch (remove all trace).
If you want to delete it, you need to hg strip it.
In Bitbucket, find the revision where the branch was created, and go to Settings > Strip changesets > <Enter "Revision to strip">.
Confirm the deletion of all the revisions attached to the revision you entered, then delete.
NOTE: This approach may not be so straight forward if you have merged. This approach is more for "I have created a branch incorrectly, I want to delete it, and recreate it again using the same branch name."
Using hg workbench, I lookup up the commit that started the new branch, right clicked and selected ## Copy Hash.
Then I enabled the strip extension by adding the following to my mercurial.ini (located at %USERPROFILE%\mercurial.ini)
[extensions]
strip =
Finally I executed the strip command using the hash from my clipboard to remove the local branch:
hg strip 36012047aee7c08cdc4ede51293392c106a3d0b7
I'm trying to get the hg-git extension working under Windows and after hours of fiddling, I finally seem to have it working. However, nothing shows up in my git repository even though the output of hg push reads:
importing Hg objects into Git
creating and sending data
github::refs/heads/master => GIT:8d946209
[command completed successfully Wed Oct 20 15:26:47 2010]
Try issuing the command hg bookmark -f master
(use -f to force an existing bookmark to move)
Then try pushing again.
This works because Hg-Git pushes your bookmarks up to the Git server as branches and will pull Git branches down and set them up as bookmarks. (from the official README.md)
And it seems that just after I asked this, I made a trivial change. This was picked up and pushed. So it seems that you have to wait until you've made a new commit in order for hg-git to pick it up.
I had chosen to 'Initialize this repository with a README'. This meant I ended up with two heads, which I couldn't hg merge because one had a bookmark.
To get pushing working, I had to:
configure hg-git and github remote as per https://blog.glyphobet.net/essay/2029
pull from github and update
force the merge (checking which id to use with hg heads),
commit the merge
add a trivial change to a file (add a space char to the end),
commit, then
move the bookmark to the tip
push to my configured github remote
This ended up with commands as follows (substituting in <x> sections)
hg pull github
hg update
hg merge <revision-id-of-incoming-git-version>
hg addremove
hg commit -m 'merged with github'
# make some trivial change to a file - eg add a space where it doesn't cause harm
hg add <changed-file>
hg commit -m 'trivial change'
hg bookmark -f master
hg push github
make sure you pick the remote revision for the merge above - if you don't it doesn't work!
Suppose that I have made some changes in the working directory and accidentally marked several files (that include some of the modified ones) for removal. How do I unmark the files for removal without losing the changes I have made?
Just hg add the files.
I don't know why you're getting some many answers that modify the working directory. If you've accidentally marked some files for removal you can undo it with add.
ry4an#four:~/hgtest$ hg status --all
M another_file
C a_file
ry4an#four:~/hgtest$ hg remove --after --force *
ry4an#four:~/hgtest$ hg status --all
R a_file
R another_file
ry4an#four:~/hgtest$ hg add *
ry4an#four:~/hgtest$ hg status --all
M another_file
C a_file
That said, don't use --force with hg remove or ever really. Also try to get in the habit of using hg forget instead of hg remove --after,
there are two options using hg revert :
hg revert -a
which will go back to the previous revision and put all your changes in new files with .orig appended to the names
hg revert [names of files to unremove] to just revert those files
i'd probably go with the latter
hg revert
I'm pretty sure Mercurial even makes backups of your changes by default.
If the file exists, (likely if you've marked it for removal with hg forget or if you've modified it then hg removed it), do hg add [file] to add it back with any changes made after the last commit and before forgetting the file.
If the file does not exist (likely if the file was unmodified and you've marked the file for removal using hg remove), do hg revert [file] to revert it back to its state in the parent of the working directory.
I had the exact same problem. hg add is the inverse to hg forget (just as the opposite is true). However, attempting to re-add the directory itself did not work. Instead, I had to use hg add on each file:
hg st | egrep "^R" | sed -e "s/R //" | xargs hg add
Hope that helps. Note that in my case, there was nothing I legitimately wanted to remove. If you have files you definitely want to remove, adjust the grep accordingly.
Following your comment to jk, I checked hg forget. It seems to be just a shortcut for hg remove -Af, meaning that this is the real opposite of hg add.
Following that, if you've used hg remove -Af, then you should be able to revert that using hg add (I just tried it and seems to work).
The markers are stored in .hg/dirstate file. All you need to do i to get a one from before issuing hg remove -Af. It may look like this (not tested):
hg clone bad-repo orig-repo
cp orig-repo/.hg/dirstate bad-repo/.hg/dirstate
cd bad-repo
hg status
The last command should show the status from before removing files.
I removed a bunch of unmodified files:
hg remove *
This is what I had to do to get them back:
hg revert --all
Nothing else worked. Not hg add not hg add * nor hg revert *