Refetching a locally deleted file from Mercurial - mercurial

I deleted one of the files that was in my repository locally (just at the file system level, not using hg remove). I now want to get that file back from the repository to my local directory. When I do hg status, it knows that the file is locally deleted, but there are no changes to be commited which is what I would expect.

$ hg revert your-file
will restore it.
Edit: see http://www.selenic.com/mercurial/hg.1.html#revert

The following will revert all deleted files in the current repo:
hg status -nd0|xargs -0 hg revert

cd to your dir and do "hg revert ." to restore all files or used any appropriate mask like *.java, etc.. This will effect only the current dir (not sure about subdirs).

Related

Purging old directories and files from a remote hg repo

I initially committed my project to a hg repo with the following structure:
myapp/
fizz/
buzz.txt
foobar.cfg
whistlefeather/
vroom-vroom-party-starter.xml
I did so using the following commands:
hg add
hg commit -m "Initial commit."
hg push
I then changed my directory structure locally to look like this:
myapp/
buzz/
fizz.txt
config.foobar
whistlefeather/
vroom-vroom-party-starter.xml
I then ran the same following commands:
hg add
hg commit -m "Changing some things."
hg push
When I go to the remote repo, I see it has the following structure (?!?):
myapp/
fizz/
buzz.txt
buzz/
fizz.txt
foobar.cfg
config.foobar
whistlefeather/
vroom-vroom-party-starter.xml
What commands can I run to push/purge the old directories/files from the remote repo (and so that it reflect the directory struture on my local machine)?
The hg add command you issued prior to your second commit did not actually remove files from under version control, but only added new ones. Now your repository is actually a melange of old and new files.
To add new files and remove missing ones, use hg addremove command or hg commit -A
It's actually simple to remember:
hg add adds files to the repo
hg remove removes files
hg move moves or renames files
hg addremove looks at current working dir and adds and removes files from the repo such that only the files still being present will continue to be tracked.
Each of these operation can be done in any sequence. And only a commit will actually create a changeset

Why hg does not clones correctly the repository?

I have a repository which will be cloned.
I go to directory of the repository and type the following command to get the branches.
hg branches
As the reuslt I get the
blank 0:4d82003d3fc7
And also I get the size of the repository using
du -sh ./
It prints
312M ./
This repository containes the following.
ls -a
. .. dummy .hg .hglf
Now when I clone it using this command
hg clone /path/libname -r blank
I get the new repository, the size of which is only 52 kbts and it containes
. .. dummy .hg .hglf
I also clone it without -r blank option
hg clone /path/libname
And get the same result. I suppose if repository have 312M size, the cloned repository also should have a comparable size. Where is a problem ?
The original repository has a '.hglf' file. This indicates that (most likely) it uses 'largefiles'. Largefiles are stored on the server, and are only downloaded for a specific revision if you update to that revision. There are a few possibilities:
You are not on a revision that uses largefiles. Update to one that does and you'll see a larger size.
You don't have the 'largefiles extension' enabled. Enable it and try to clone again, you should see a difference. To enable largefiles, add to your .hgrc:
[extensions]
largefiles =
Starting with Mercurial 3.4 (not yet released as of this writing), the largefiles extension will be enabled automatically when cloning a repository with largefiles.

How to fully remove file in repository?

I add a file with commit and push it to repository. If I remove the file with new commit, this file all the same will locates in repository (concept of version control systems). Can I delete this file from repository fully (File and all information about this file in a commit history)? I want remove it to have possibility to back on previous commit and haven't troubles with requirement of this file availability in repository.
Make this command, to remove the files in repository
hg addremove
With the command hg status , you can see what will be remove, with ! symbol before the file. For example
# hg status
! src/main/filex
! src/main/fileY

abort: untracked file in working directory differs from file in requested revision: '.hgignore'

I am trying to pull some files and directories and I am having the following messages:
When I look in my repository I can see that the files have been downloaded but all contains _ as prefix, and even the names of files and folders contain _
requesting all changes
adding changesets
adding manifests
adding file changes
added 1094 changesets with 4304 changes to 1071 files abort:
untracked file in working directory differs from file in requested revision: '.hgignore' [command interrupted]
What is wrong?
I think you have created a .hgignore in your working directory without adding it to the repository (hg add). This file is "untracked".
Someone else, from another clone, has added this file too, committed and pushed it. Now, when you try to update your working directory, Mercurial try to add this file but sees a file with the same name in your working directory which is untracked and different.
There's two solution to your problem :
Backup your .hgignore file, do the update and add the differences from the backup if necessary
Add your own file to the repository with hg add, then re-run the update. It will maybe be necessary to commit the file prior to the update.
I'll advise using the first solution.
When you say the files in the repository have _ as a prefix, you're looking down inside the .hg directory aren't you? That's the data store for Mercurial itself and the files in there are revlogs, not your files. Outside of .hg you'll have a working directory where the files are the actual files you expect. You're not getting one of those now because hg update is refusing to update the working directory because doing so would overwrite your uncomitted .hgignore file.
What exact command are you running? It looks like it's doing a hg pull followed by an hg update so I'd guess hg clone but if you already have a .hgignore lying around that's not the right command to use. If instead you're using hg pull -u or hg fetch you should just use hg pull instead to get the changesets. Then you can:
hg add .hgignore # add the hg ignore file you already have that's untracked
hg commit -m .hgignore # commit the .hgignore file you just added
hg merge # merge your new commit (.hgignore) with the changesets you just pulled down.

Mercurial Newbie confused

I am familiar with TFS and Vault, but having just started using Mercurial I seem to be getting into a bit of a mess.
Heres what I (think) I've done:
-Created a central repository on bitbucket.org
-On my desktop PC, cloned repository from bitbucket, added files, commit them, push them to bitbucket
-On my laptop, cloned repository from bitbucket, pulled files, added more files, commit them, push them to bitbucket
I've continued to add, edit etc on the different computers.
Now I've noticed that some files from each computer are not in the bitbucket repository, and therefore only in the local repository. No amount of pulling and pushing seems to get it into the bitbucket repository.
What is the most likely thing I've done wrong?
Is there a way to 'force' by changes up to the bitbucket repository?
Did they get into your local repository? I suspect not, i.e. they were new files that were not added to the commit. Use hg add to add them to the changeset before committing or whatever the equivalent is for whatever mercurial interface you're using.
Edit:
Here's the help from Mercurial:
C:\Users\Bert>hg add --help
hg add [OPTION]... [FILE]...
add the specified files on the next commit
Schedule files to be version controlled and added to the repository.
The files will be added to the repository at the next commit. To undo an
add before that, see "hg forget".
If no names are given, add all files to the repository.
...
See Mercurial: The Definitive Guide (a.k.a. the hg "red book") for more info:
http://hgbook.red-bean.com/read/mercurial-in-daily-use.html
Telling Mercurial which files to track
Mercurial does not work with files in your repository unless you tell it to manage them. The hg status command will tell you which files Mercurial doesn't know about; it uses a “?” to display such files.
To tell Mercurial to track a file, use the hg add command. Once you have added a file, the entry in the output of hg status for that file changes from “?” to “A”.
$ hg init add-example
$ cd add-example
$ echo a > myfile.txt
$ hg status
? myfile.txt
$ hg add myfile.txt
$ hg status
A myfile.txt
$ hg commit -m 'Added one file'
$ hg status
use "hg -v help add" to show global options