How to cleanup Mercurial repository? - version-control

I need to delete my "uploads" folder from the repository with all its history because it contains only junk testing data.
Please help.

You'll want to use the convert extension that ships with mercurial. Since you want to scrub a directory from the history you'll have to completely filter you're existing repository, CONVERTing it into a new one.
Assume the following made up structure of your repo:
/
src
doc
images
upload
Create a simple text file with the following content
exclude upload
You can do more with this file but keep it simple to get to your goal. The path to be excluded is relative to the repository root
Now run mercurial convert
hg convert --filemap path/to/the/textfile old-repo new-repo
Change to the directory of the new repo. Notice that mercurial created a bare/null rev repo (no content but the .hg directory). Run the following to update to your latest changset. Notice the upload directory is gone!
cd path/to/new/repo
hg update
WARNING: I do not know how this handles named branches or tags. You're on your own. At least you're not modifying the original repo. Make as many copies as you need to get it right.

Related

How do I add a file in a subfolder to a new repository?

I have a repository for a website and it has two separate remotes. One is for the website files and one for datasets and R scripts to make some data in my blog posts reproducible and archived for the future.
My local file structure looks like this.
-Website
|
|--website-files/posts/blog-post1
|/blog-post2
|r_script.R
The folder Website has two remotes one - origin - for the website, and one - blog-post - for the dumping ground for my replication files.
So, because I have cleanly added a second remote, I tried to add the file r_script.R and push it to the remote blog-post.
git add website-files/posts/r_script.R
Then, though, when I check the status, git status shows the file name as untracked listed as
../../r_script.R
The precise question: How do I add a file in a subfolder to be tracked and then to push its own unique remote? Note, when I copy r_script.R to the folder Website, and run git add r_script.R it shows up as a staged file ready for committing.
But I would really rather keep it in the subfolder to keep it clean.
Maybe should I add the repo blog-post as a submodule to the subfolder website-files/posts/ or something like that?

How to get source code from GitHub data export?

I decided to backup all my github data and found this: https://help.github.com/en/github/understanding-how-github-uses-and-protects-your-data/requesting-an-archive-of-your-personal-accounts-data
I managed to get the .tar.gz file and it seems to contain all my repositories but there is no source code in there. Judging by the size, it looks like some kind of archive in objects/pack/*.pack
Is there any way to access original source code?
it looks like some kind of archive in objects/pack/*.pack
According to Download a user migration archive:
The archive will also contain an attachments directory that includes all attachment files uploaded to GitHub.com and a repositories directory that contains the repository's Git data.
Those might be bare repositories or bundles.
Once uncompressed, try and git clone one of those folders (to a new empty folder)
The OP johnymachine confirms in the comments:
git clone .\repositories\username\repository.git\ .\repository\
Meaning repository.git is a bare repo (Git database only, no files checked out)

CVS branch actual location on server

The CVS repository in my project has a HEAD code and 8 other branches. The server location mentioned as '/local/cvs/srcjboss' contains only the projects in the HEAD branch.
Is there a physical location on the server where all the branch code can be accessed ? I need the server location for CVS to SVN migration.
If it helps, we are using a linux server
To convert a CVS history to Subversion using cvs2svn, you need filesystem-level access to the data from the central CVS repository. It is not enough to have access to a working copy where the code is checked out. It's not really clear from your question which of these you have under /local/cvs/srcjboss.
A CVS repository is recognizable from its CVSROOT subdirectory and lots of files named like your project files, but with ",v" appended, like maybe "Makefile,v" or "index.html,v" or "build.xml,v". Each of these files contains the entire history (including branches) of the corresponding file from your project, in rcsfile(5) format. The repository probably also contains "Attic" subdirectories that hold the histories of files that are not present in HEAD.
A CVS working copy, on the other hand, contains one particular version of each file (with no ",v" suffix), plus a CVS subdirectory in each of your project directory. A CVS working copy doesn't contain any of the project history.
So is your /local/cvs/srcjboss the CVS repository or is it a working copy?
If you have a working copy and are trying to find the central repository, look in one of the files named CVS/Root. It will tell you the location of the repository from which the working copy was checked out.

Change root directory of repo in Mercurial

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.

How can I move my Mercurial repository root up one directory?

I have a directory structure like:
project_root
data/
src/
.hg/
utils/
math/
graphics/
...
README.txt
LICENCE.txt
As you can see from the location of .hg/, only src/ is under Hg control. I'd like to move the repository root up from src/ to its parent directory project_root, so I can track data/, README.txt, and LICENCE.txt as well.
A hacky way to do this would be to move everything down a directory rather than moving .hg up:
Move the contents of src down to a new directory src/src/
Move the contents of project_root (other than src/) down to src/
Rename src to new_project_root
Move new_project_root out of project_root, delete project_root
Is there a better way? I can't be the first person with this problem, and the above solution seems overly involved.
You should try hg convert. You will be "converting" your existing Mercurial repo into a new one. You specify rules for the conversion, which in your case will be that all files from the original repo go to a src directory in the new repo. Then you can manually copy and hg add the other files to the new repo.
This has the advantage that it won't be reflected as separate changes in your history. The possible disadvantage is that it will cause your changeset IDs to be regenerated, and existing clones will no longer be able to pull from the new repo.
Your plan is fine. It may seem involved, but it should take less than 20 minutes (worst case) and only happens once.
In the first step when you move the files that are tracked, you should use hg rename (alias hg move) to move them, as Mercurial will remember what each file was before and after the move. This will help with merging changes on file prior to the move with the new files after the move. Works best when renaming/copying is not accompanied by changes to the contents in the same changeset.
I recommend cloning the actual repo (or copying the entire project directory) before proceeding.
hg's Detect Renames works a treat nowadays.
Clone the repo so that you can mess things up without worry.
Using your example:
create the src/src subdir
move utils, math, graphics etc into src/src
Then open the commit window.
the moved files will appear in their old directory with a ! and in their new directory with a ?
right click on any file and choose "Detect Renames..."
slide the Min Similarity slider to 100%
Click the Accept All Matches button, and close the Detect Copies/Renames window
the moved files should now appear with an R in the old directory and an A in their new directory
commit this change
Then I moved data, Readme.txt etc down into src (not src/src)
committed the adds.
Finally, now that I have the repo as I want it, push the changes back to the originally cloned repo. Don't forget you'll need to Update the original repo to see the changes in the working directory.