I'd like to output ("-o") the content of a file that is version controlled in mercurial. I know this can be done using the cat command.
However, the file I am interested in has been removed, so the cat command fails with a "no such file in rev X" where X was the revision number where the file was removed.
I do not wish to restore the file. How do I output the content of such a file?
One alternative to using cat would be to update to a revision where the file still existed. This would just be:
hg up -r$REV
as long as you're sure it still existed in $REV. Then you can just navigate to the file normally & view it, copy it somewhere, etc.
The usual considerations apply when doing any update - i.e., you generally need a clean working directory.
If you are using TortoiseHG, you could also use the "browse" feature to do something similar.
In THG Workbench, scroll down to the revision that still has the file. Then right click "Browse at Revision". This will show a treeview of the entire repository at that revision. You can just pick the file out of the tree and save it, etc.
hg cat -r$REV $FILE
where $REV is the revision of the file you wish to view and $FILE is the filename.
If you are unsure of the revisions you can use hg log $FILE to show you the history, so you can choose a revision before it was deleted.
Related
I've done this several times in git, but not sure how to do it in p4 commandline. Google is not helping me - or maybe I'm not searching correctly.
I have a file that was deleted: /path/to/file/index.html Now, I need to get the contents of that file as it was before being deleted. I do not want to bring it back to life, I just need the contents.
The changelist for the delete is 125325.
What would be the easiest way to do this?
To sync it to your workspace (this is kind of similar to the git checkout method that you're probably familiar with):
p4 sync /path/to/file/index.html#125324
If you just want to see the content (e.g. dump it to stdout), you can use p4 print (if you were to use the depot path of the file rather than a local path, p4 print doesn't require that the file is mapped to your workspace):
p4 print /path/to/file/index.html#125324
Note that the rev specifier I'm using is the changelist before the file was deleted. You can also use the prior revision number, or an earlier rev/changelist, a particular date, etc. See p4 help revisions for all the ways you can reference older versions of files.
I'm looking for the opposite mechanism to the .ignore file, which should add all files of a given pattern automatically, for example *.tex for any LaTeX documentation project or *.def for any file that was added by OASIS (an MS Access addin for version control).
hg add with no arguments will add all files not explicitly ignored. You can also use hg commit --addremove to add all unknown files (and remove all deleted files, i.e. hg rm any which hg status lists as '!') to do this automatically when committing.
Adding files only happens when you run hg add. If you want to add all files matching a pattern, use the --include (-I) switch.
I have a file that needs to be brought into a different branch. How do I do this from the command line. Everything seems to be geared to merging, where the file already exists in both branches.
You have to merge the parent directory first, so that the file shows up in the directory in the destination branch. At this point the new file will have zero size. You can then merge the file itself. The easiest way to do both of these operations is via the Version Tree view - much less error-prone than doing it via the command line.
Much simpler:
1/ rmname the file in the destination directory
ct co -nc .
ct rmname -force file.txt
2/ merge the directory
ct findmerge . -ftag view_tag
with 'view_tag' a view on the source directory
I no longer have access to a clearcase environment, so this is from memory, but what you want is to link in a version from another branch into the one that you are working with.
Let's assume that you have a file new_file that have been added on the branch new_feature (the latest version is new_file##/main/new_feature/5) which you want to merge/bring into the branch maintenance.
prompt>cleartool checkout -nc .
checking out some_dir##/main/maintenance/2
...
prompt>cleartool ln .##/main/new_feature/LATEST/new_file/main/new_feature/5 .
...
prompt>cleartool ci -c "linked in .##/main/new_feature/LATEST/new_file/main/new_feature/5"
prompt>
The commands above are probably not 100% correct, but should give you the idea. You want to use cleartool ln to avoid evil twins, because that will bring in a version from the already existing element (i.e. not creating a new twin).
I have a file with database settings in my project which I have set to some defaults. The file is tracked by Mercurial and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Mercurial to ignore new changes to this file?
I tried adding the file to the .hgignore file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?
Using a file template is definitely the best solution.
For example, if you have a database.ini file, commit a database.ini.template file and ignore database.ini in .hgignore
If you always want to ignore the file, you can add the -X option as a default for commit to your .hg/hgrc configuration file:
[defaults]
commit = -X program.conf
We wrote an extension for this called exclude. It will automatically add the -X options on the commands that support them -- so hg status and hg commit wont see the modified file. It works by reading a .hgexclude file from the root of your repository, just like the .hgignore file. You add the files that you want to exclude there:
syntax: glob
db.conf
The extension works quite well, but there is a known situation where it fails: merges and the commit that follows a merge (this is documented on the wiki). It would need to be improved so that it would save the modifications away to a temporary file and then restore them afterwards. Please get in contact if you need this feature.
There is no truly automated process, but you can try (as in this SO question) the -X option on hg commit:
% hg stat
M myfile
% hg commit -X 'myfile'
(other solutions might involve shelve or hq)
However, this is not the "right" solution. I would rather recommend versioning:
a file template
a script able to generate the final file (that you modify but can ignore altogether)
If you are using TortoiseHG, open the Settings for the repo, go to the Commit section (2nd icon down on the left) & add the file name(s) to the Auto Exclude list on the right (~ 3rd from the bottom in the list).
From https://tortoisehg.readthedocs.io/en/latest/settings.html#commit
Typically you would check in a reference copy of the file and track it then have the developers make a copy of that for local development, you wouldn't really want developers editing the source controlled file for their own environments.
If your configuration system supports it, it's even easier if you can use an override file that simply override values in the reference copy (e.g. the database connection string). That way devs only have to keep a very minimal local set of override values.
If the file is already being tracked, you can issue the Forget command to the file. If you're using TortoiseHg just right click the file during commit and select Forget. The file must also be already in the ignore list.
I had the same problem as yours, I file keeps on appearing on every commit even-though its already in the ignore list. I tried the Forget command and it did the trick.
You can try hg forget.
For more details, see the official manual about the same command.
It worked for me.
I think, something like this is closer to a correct answer to the original question Mercurial: How to ignore changes to a tracked file, rather than the others suggesting a template, etc.
Please note: This is a question about the Eclipse plugin Subversive, and not about Subversion itself. Please do not change the title to be about 'Subversion'.
So I deleted a file that I really shouldn't have.
I've found various approaches to restoring the file outside of Eclipse/Subversive, but I was wondering if there was a best/easiest-to-use/history-restoring way to restore the file using the Subversive tool.
Select the folder in the project that contained the deleted files.
Right click, select Team > Merge...
On the URL tab, set the URL to the server URL for the same folder.
In Revisions, select Revisions and enter a range that includes the deletion, e.g. 1000-1001, or use the Browse button to select them.
In Revisions, enable Reversed merge
Click Preview and check that it shows an Added entry for the files you plan to restore.
Click OK - Eclipse switches to SVN Merge in the Synchronize view.
In the Synchronize view, right click the files you want and select Accept
In the Synchronize view, use the Synchronize SVN icon to switch from SVN Merge to SVN, where you can see the restored file as an outgoing change.
If you have already submitted the remove then it's now time to roll back to the earlier version. In Subversion you do that with "svn merge", where you merge "backwards" from the current to the previous version.
Say you did this:
$ svn rm file.txt
$ svn ci -m "don't need that file"
Committed revision 1325.
Now you want to undo this and restore the old revision 1324, i.e. the state just before the remove (the dot is for 'current directory'):
$ svn merge -r1325:1324 .
If you are unsure you can do a dry-run first, where svn will print the output of the command, but not actually do anything:
$ svn --dry-run merge -r1325:1324 .
The result should indicate that the file is being added (again):
A file.txt
you could switch to revision where this file was exist. Edit/copy this file and switch back to the head revison and commit it here.
Also you could merge changes beetween two revisons - head and last revision file was exist in repository and apply changes to your working copy.
Just "Show History" on the folder, file was existing in. Then click through the history and find the lost file.
I guess you're hoping to not resort to the command line but in case it's useful as a last resort, see this question for how to do it from the command line: What's a simple way to undelete a file in subversion?
Easier: try to commit, Eclipse will show you the dialog with the changed files, click on the one you want to delete with the right button and pick "Revert".
I had a similar issue, I deleted a set of files related to a feature that after a couple of months I want to recover.
The most straightforward solution in my case was to check out in a separate directory the whole project as it was before the file were deleted.
To do this from the Eclipse Repository View go to your project, right click "Check Out As...", in the modal window write the destination folder, select a suitable date of the past in which the deleted file existed (weird, my plugin does not give the possibility to choose a given revision..) and check out.
Now you can easily search, find and copy-paste the files you want to recover.