I would like to put directory C:\WorkDir under Mercurial version control, but have the repository located somewhere else than C:\WorkDir\.hg perhaps D:\Repositories\WorkDir.hg. Is that possible in Mercurial?
This answer on the Mercurial mailing list by Martin Geisler is quite clear about it:
You cannot move the .hg folder outside of where your working files
reside. That is by definition: the "working copy" is the parent
directory of the .hg folder. So if you want to version files in
C:\inetpub\laravel\app
you must have
C:\inetpub\laravel\app\.hg
If you want to avoid having the drive with the "real" working copy filled up with the repository data, you can use the share extension: https://www.mercurial-scm.org/wiki/ShareExtension .
E.g. if you want to version control C:\WorkingDir, but want the big repository data to reside on D:\Repositories\WorkDir, just do the following:
cd D:\Repositories
hg init WorkDir
cd C:\
hg share D:\Repositories\WorkDir WorkingDir
You will still have a .hg directory on C:, but it will remain really small (around 1MB), while the repo on D: will be the one that grows with time.
Have you tried creating a Junction?
Let's say your repo is c:\test\.hg but you want to put .hg directory in c:\shadow
mkdir c:\shadow
mv c:\test\.hg c:\shadow\.hg
mklink /j c:\test\.hg c:\shadow\.hg
Related
I have the folder called, SpartanDrive-hansol, as you see in the picture, and it contains all the necessary files that I need. But just the folder, SpartanDrive-hansol, is unnecessary, and it causes a problem when I try to merge it with master branch because master branch does not have that folder.
Can anyone help me how to delete the unnecessary hierarchy of the folder? (But I need all the files that are in the folder) Thank you!
You can do it easily with the terminal. In the parent directory of the SpartanDrive-hansol folder, run the following command in the terminal:
mv SpartanDrive-hansol/* .
This will move all contents of the folder to your current folder, which in this case is the parent folder.
I've been using this folder structure where I would have one main .git folder and then have subfolders inside which doesn't have .git folder.
So as example :
Main Folder
Subfolder
Subfolder
Subfolder
Now what I want to do is, I would like to extract some of those subfolders and make them separate repositories with their histories. Which means subfolders will become a main folder as a repository. Any idea how?
The official documentation use git filter-branch.
But that or BFG are obsolete.
Use the new tool git filter-repo (directly in your regular local repository, although a backup is always a good idea before those kind of filtering)
Use a path shorcut:
git filter-repo --subdirectory-filter Subfolder1
Only look at history that touches the given subdirectory and treat that directory as the project root.
Equivalent to using --path / --path-rename /:
I meant, I don't need all the ".bzr" folders under each directory (I may have hundreds of nested ".bzr" folders); I want to check out those actual files only. Thanks!
Are you really sure you have hundreds of nested ".bzr" folders? There should be only ONE .bzr folder per project, right at the top level directory of the project, no additional .bzr folders in subdirectories. (You might be mixing it up with Subversion?)
It seems that maybe you want to get all the project files without any .bzr folders or Bazaar files. If that's the case, cd to your project and run any of these commands:
bzr export /tmp/project-as-dir # export files into a directory
bzr export /tmp/project.tar # export files into a tar file
bzr export /tmp/project.tar.gz # export files into a tar.gz file
Simply remove the folders, e.g. using find -type d -name .bzr -exec rm -rf {} +
Note that you won't be able to use bzr in that copy anymore (i.e. you can't commit stuff etc.).
I'm working on an Android game with the folder structure:
\bin
\data (contains game graphics)
\libs (libgdx engine jars)
\src
----\com
--------\brand
------------\game
(*.class files)
Foolishly, I created a mercurial repository (hg init) in the \src directory. Thus, if I update any of the graphics (small file sizes), they aren't added to the repo when I commit. My question is: how can I change the root of the repo to include the \data directory as well as the \src directory, but without including the \libs directory as that includes 10-20mb jars?
There are two ways to do this.
1) Start a new repo. It's quick and easy but you'll lose your history.
2) Use hg rename. This is effectively a move command.
Rename the src directory to be something meaningful and then do this.
hg rename MyProject/com MyProject/src/com
Copy all the files/folders into the MyProject/ directory.
Mark bin and libs as ignorable and
Add everything else.
hg commit
If you don't want to just do an hg rename, you can do it with the convert extension (which comes by default with Mercurial, you just need to enable it in your .hgrc).
Run it with the --filemap parameter and a filemap file that has something like:
rename com src/com
You will end up with a new repository with all of your history, but with your com directory moved into src/com. You can then copy you bin, data and libs folders in there, run hg addremove and you should be all good to go.
Warning: the new repo is completely different than the old one -- changeset IDs and such will be different, so anybody you worked with in the past will have to get on the new repo.
I've been using ComponentSoftware's CS-RCS Basic for many years now to manage my various single-developer projects. It's worked very well for me, but now I want to migrate to a modern revision-control system, and after studying my options I decided on Mercurial.
The problem is that I've always used a central repository for CS-RCS, and I'd now like to use individual Mercurial repositories for individual projects, keeping the history from my RCS repository.
After some in-depth Googling I concluded that the only way to do this is to convert my RCS repository to individual CVS repositories, then convert those to Mercurial. These two sites were probably the most helpful:
Converting a directory from RCS to Mercurial
Convert Extension for Mercurial
In keeping with Jeff Atwood's idea of asking and answering my own question, I'm going to answer this for anyone else stuck in this situation, and in case I have to find it again later. As you'll see, though I did find a solution, it's clunky and has at least one significant problem. If anyone else has any better method I'd certainly like to hear about it.
Here's the method I came up with, warts and all. It's a bit 'cargo culty', since I basically know nothing about CVS and not much (yet) about Mercurial:
I have a Windows XP virtual machine that I can take snapshots of, so I did that and then installed CVSNT and the Windows command-line version of Mercurial (I use TortoiseHg on my main machine). I did this in a VM so I could easily get rid of CVSNT, Mercurial, and anything else I had to create while doing this one-time migration. Yeah, I probably didn't have to do this, but the VM was already available and I've already got enough odd bits of apps left over from install/uninstall cycles over the years. :-)
As far as I could tell, CVSNT was the only program available that could easily set up a CVS server on a Windows machine. It seems that this was free at one time but the owner's current site now asks for money. That's not a bad thing, but I really couldn't justify spending money just to do a one-time conversion. I did eventually track down an older version of CVSNT with a Google search and installed that without problems.
Here are the notes I took while learning how to make this conversion work:
The Long Version
Copy the source-code folder you need from the main computer's drive to the VM's drive. Copy the various ",v" files from the C:\RCS folder structure to this same source-code folder on the VM. Just copy the ,v files from the corresponding folder in C:\RCS.
Open a Command Prompt box on the VM and type the following:
path %PATH%;C:\Program Files\cvsnt
mkdir \cvs-repo [or clean the folder out if it already exists]
cvs -d \cvs-repo init
[A DIR of \cvs-repo should show a CVSROOT folder in there.]
Make a copy of your source code folder in \cvs-repo. \cvs-repo should now just have two folders: CVSROOT and your new folder. Copy in the appropriate ",v" files as well.
mkdir \cvs-checkout [or clean that folder out if it already exists]
cd \cvs-checkout
cvs -d \cvs-repo co name_of_your_source_code_folder
A DIR of "\cvs-checkout\name_of_your_source_code_folder" should show all of your source code files, which are now checked out of CVS.
If you haven't already done so, download Mercurial from https://www.mercurial-scm.org/ and install it. Open a copy of Notepad and drag the file "C:\Program Files\Mercurial\hgrc.d\Mercurial.rc" into it. Under "[extensions]", remove the semicolon at the start of the line ";convert =". Save the file to "C:\Documents and Settings\user_name\Mercurial.ini"
Back at the VM command line:
path %PATH%;C:\Program Files\Mercurial
mkdir \my-repo.hg [or clean that folder out if it already exists]
hg convert --datesort \cvs-checkout\source_code_folder_name \my-repo.hg
cd \my-repo.hg
[A DIR of \my-repo.hg should show a new ".hg" folder.]
hg update
[A DIR should now show the ".hg" folder and all the checked-out files.]
Copy the ".hg" folder from \my-repo to the source code folder on your main computer's hard drive. The destination folder will now show up in TortoiseHg with all of the appropriate change history, but all files marked as Changed (icon overlay of an exclamation mark in a red circle). This is because the new Mercurial repository thinks the files were checked in with Unix line endings (0x0A) instead of Windows (0x0D,0x0A). This seems to happen in the "hg convert" process, and I haven't found any way around it.
The Short Version
Once everything's set up in the VM, here's what to do:
Delete everything in \cvs-repo, \cvs-checkout, and \my-repo.hg.
At the command line, cvs -d \cvs-repo init.
Back on your main machine, copy the source-code folder into your Virtual Machine's shared folder (that's how you do it in VirtualBox; other VM software might let you just drag-and-drop the folder into the VM).
Copy the appropriate ",v" files into the source-code folder in the Virtual Machine shared folder.
Back in the VM, move the source-code folder to \cvs-repo.
cd \cvs-checkout
cvs -d \cvs-repo co name_of_your_source_code_folder
hg convert --datesort \cvs-checkout\name_of_your_source_code_folder \my-repo.hg
cd \my-repo.hg
hg update
Copy the .hg folder from \my-repo to the L: drive on the VM (L is the mapped drive letter of my VM shared folder).
Move that folder from the Virtual Machine transfer folder to the final source-code folder on the host computer.
Handy Batch File
Once I got this working, I set up this batch file on the VM to automate the process as much as possible:
#echo off
rem Converts source code under RCS control to a Mercurial repository.
rem This batch takes one argument: the name of the source-code folder (in quotes if necessary).
rem
rem This is for a VirtualBox VM that already has CVSNT and Mercurial installed, and has a Shared Folder mapped to drive L.
#echo On the host, copy the source-code folder into the Virtual Machine Transfer folder. Copy the appropriate ",v" files into the source-code folder in the Virtual Machine Transfer folder.
pause
#echo on
cd \
rmdir /S/Q \cvs-repo
mkdir \cvs-repo
rmdir /S/Q \cvs-checkout
mkdir \cvs-checkout
rmdir /S/Q \my-repo.hg
mkdir \my-repo.hg
cvs -d \cvs-repo init
xcopy L:\%1 \cvs-repo\%1 /E/I
cd \cvs-checkout
cvs -d \cvs-repo co %1
hg convert --datesort %1 \my-repo.hg
cd \my-repo.hg
hg update
xcopy \my-repo.hg\.hg L:\.hg /E/I
Conclusion
So, this all worked but left me with files that had the wrong line endings. Looking at this question, I see I'm not the only one with this problem. I can live with this, but I'd still like to fix it if anyone knows of a solution.
If Mercurial has fast-import/fast-export support, and if your multi-file repositories do not use branches, you can probably try using my rcs-fast-export tool (available # http://git.oblomov.eu/rcs-fast-export ). Although I've only used it to export from RCS to git so far, I am not aware of any git-specific fast-export commands being used so it might work.