Mercurial overwrite a tracked file with an untracked file - mercurial

I have a tracked data file which I would like to overwrite with a newer (currently untracked) version
How do you achieve that in mercurial without messing up the history?
Can I just overwrite the original file, so long as the filename stays the same, and everything should be OK?

Overwriting works just fine. Only problem is that mercurial considers that you have made changes to existing file.
If the new file is really unrelated to original file the best way to do this is to completely remove that file (hg rm filename) and commit the removal and then create the file with the same name and add it to repo (hg add filename) so that its clear to the user that the original file was deleted and then a new file was created.
hg rm filename
hg commit -m "Removed filename"
echo "New file contents" > filename
hg add filename
hg commit -m "New version of filename"
When you say
hg log filename
the entire history of the file is anyway preserved and its clear to the user that the old file was deleted and new file was added.

Related

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

How to allow a deleted file to remain untracked in Mercurial?

I've got a configuration file ("config") that we originally committed to our repository. (first mistake)
We then deleted that file using hg rm, and left a sample configuration file in the repository.
When developing, we just copy the "config.sample" file to "config". However, whenever I update to a different branch and back to the branch with the delete, the untracked config file is deleted.
I've already added the config file to .hgignore.
Is there a way to make mercurial allow the existence of this untracked file going forward?
It looks like the branch you go to before coming back contains a config file too. When updating back, the file was deleted, so mercurial removes it.
Try deleting the config file in your other branch, too, and adding the file in the .hgignore of that same branch.

hg convert with filemap giving empty repository

I have got a new repository converted from SVN. I want to minimize this repository further by removing unintended files.
For that I am again converting the mercurial repository to a new one by using hg convert and the filemap parameter.
So my filemap looks like this:
include a
rename a .
The command I am using is:
hg convert --filemap fm.txt . ../new_repo
This ends after full conversion as I can see in the console output.
But if I now check the content of the directory new repo, I can see only .hg files in there.
I ran hg update -C within the directory whic gives me one more file .hgtags
Can anyone please suggest what has gone wrong?
This answer was spot on: you don't actually create an empty directory, but a directory with a hidden .hg directory. If you run
hg update
in your target directory, you will have your target directory with all its contents as expected.
In common, you done all correct (if directory a exist in source repo)
In my test for repository with directory lang, which I want to move into the root of new repo, I used filemap
include lang
rename lang .
identical to your filemap and got bare repository after converting (no files in Working Dir, only repository on .hg). Testing repository
hg log
changeset: 19:41e96453fa67
tag: tip
...
changeset: 0:ba52ea5c5c1f
showed me all related hisory
hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(without -C) brings all files into the Working Directory
SR>dir /B
.hg
UTF-8

Refetching a locally deleted file from 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).

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.