So I accidentally included a config file (different for each machine) into our mercurial repositories.
How can I get Mercurial to not include it in version control? I don't want to delete the file since I still want it. And I don't want to cause the file to get deleted on other developer's working directories either.
And how do I do this in TortoiseHG?
Right click on the file -> TortoiseHG -> Forget Files. Click Forget. Commit and Sync.
Edit:
You'll also want to add the path to your .hgignore to keep it from getting added again. You can right click on the file in the HG Commit dialog and choose to ignore it.
Here's the manual way of doing it through the command line:
Copy the config file somewhere outside of the repository.
Run hg rm path/to/config/file
Add the config file path to your .hgignore.
Commit the repository.
Move the config file back to where you had it.
Do an hg stat on your repository to double check you did everything right. (It shouldn't show up in the list of modified/added files).
Edit:
hg forget is the best way to do this.
Run hg forget path/to/config/file
Edit your .hgignore and add the path to the config file.
hg ci to save your changes.
Run hg stat to ensure everything worked according to plan.
See nates answer for how to do it TortoiseHG.
hg remove or hg remove -f?
I think hg forget also removes it from the branch.
In both cases, files are retained in your directory.
For those using SourceTree, there is an option Stop Tracking when you right click a file, it basically does the same thing as hg forget or git rm --cache, removing the file from repo but not from hard disk.
add it to your ignore list.
See the .hgignore file.
TortoiseHG gives you access to this config file via the "Edit Ignore Filter" menu option.
Related
How to move files (to subfolder) without losing their history?
In my Mercurial repository (I mean the folder with the .hg in it) I have MyProject/ folder with all project files. Now I need to create src/ folder inside and move all files to it (from MyProject/ to MyProject/src/). How can I do it without losing all history?
Since you have a "tortoisehg" tag, I figured I'd explain the way I do this using the GUI.
Usually, I just rename/move files in my IDE, or from windows explorer, then when I go to commit, THG will show a bunch of (?) unknown files and (R) removed files. Just right click on any of the files and choose "Detect Renames...", then click the "Find Renames" button.
You might have to adjust the "Min Similarity" slider until you get all the files you want and only the files you want, but it's usually very straightforward.
hg mv
does do the right thing, but hg log does not list entries past the move unless you
give it the -f option. See this question for more info
Why 'hg mv' (mercurial) doesn't move a file's history by default?
After you do this, you likely want to add the -f option to hg log
to the hgrc file for the repo.
.hg/hgrc
[defaults]
log = -f
In Windows with Tortoise HG installed, there is a windows shell extension that handles this very nicely.
In Windows Explorer, simply right-click and drag the file(s) you wish to move into the destination folder. You are then presented with a pop-up that give you these choices:
HG Move versioned item(s) here
HG Copy versioned item(s) here
Use hg mv to move your files and then use hg log -f (follow) to see history including renames.
Say I type hg add in Mercurial, and there a bunch of untracked files in my working directory that are not ignored. What is the easiest way to un-add all those files without explicitly typing the name of each file?
Can I just un-add them all with one command?
Preface
You must always ask questions, which contain as much information as possible. Because now your question, depending from some conditions, may have totally different answers.
Case One - no local modifications in already versioned files, only added (and not committed) files
hg revert will return your working directory to the state after the last commit, undoing all changes it it.
Case One - local edits, which you want to save and occasionally added files
Read about filesets in Mercurial.
Use fileset in the hg forget command, something like hg forget "set:added()".
Use hg revert or hg forget on the files (both do the same for a file you ran hg add on). To avoid typing out the filenames, you can use a fileset like this:
$ hg revert "set:added()"
This will revert the file back to how it looked in the working copy parent revision, i.e., it will become unknown again.
hg revert -r .^ path-to-file will revert the commit from the commit-set.
then commit and submit (if using jelly fish) and you'll see the files removed from the changeset. I don't know why .^ works yet, but somebody will probably know.
You could always just re-clone your repository and then replace (delete existing and then copy new) the .hg directory in your working folder with the one from the fresh clone... (assuming you have no pending commits..)
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).
When I started my Mercurial project I forgot to exclude everything under my target/classes directory, such as:
target/classes/com/mypackage/MyClass.class
Now these binary files are causing conflicts when I do a hg update.
Is there a single command that would allow me to delete all of these files from the entire project history?
Or, if not, is there a command that would allow me to remove them one file at a time?
If you just want to remove files from last revision, remove files from disk and use hg addremove or hg remove --after target/classes/com/mypackage/*.class to inform Mercurial about your deletion.
If you want to permanently remove all class files from you entire history use hg convert and --filemap option to rewrite your repository and get rid of files from all revisions. However this solution alters revision ids. In multi user environment it may cause some problems because it creates a new repository effectively.
If you delete the files in question then do hg addremove then the files will be removed from the repository. However they will still be in the history though, but is that really a problem?
Use hg remove --after target/classes/com/mypackage/*.class. (--after will avoid deleting the on-disk files).
Am having problems removing a file from Tortoise.
I make the clone, and there are a few test files which I want out. What is the proceedure for removing a file from the repository,
thanks in advance,
Right-click on the file(s) and click the TortoiseHg --> Remove Files... and then confirm the dialog. Commit to save the change to your local repository. Note that this will delete the file from disk and from Mercurial.
If you'd like to remove a file from Mercurial but keep the file on disk, you can click TortoiseHg --> Forget Files.... Then you may want to add the file to your .hgignore list (you can do this graphically through the Commit or View File Status dialogs) so that you don't add it accidentally in the future. Then commit.