How do you remove a Mercurial repository - linux

I accidently put a Mercurial repository in the wrong place. How do I remove it? This is in Linux.

Recursively remove the .hg directory? You can also just move it; they are portable, and the setup files inside of .hg contain no absolute paths that would break if placed elsewhere on the system.
From the comments: rm -r .hg

Related

Git: Recovery of files possible after local remove before push?

I wanted to "clean" my git repo before pushing by removing every JPG file, so I entered:
find . | xargs rm *.png
in the git root and now everything is delted. Also my *.py files are deleted, but I do not know why? It is a Linux, Ubuntu machine. Is there any chance to recover my files? Maybe over my OS?
The command you typed is plain wrong:
find .
This command outputs the name of every file and directory below ., including hidden files.
xargs
This command takes its input and runs the command given as its argument, feeding it one line at a time as an argument. Therefore, it will run rm *.png <line1_from_find>, then rm *.png <line2_from_find>, etc.
There is no safeguard like stop on errors, so if you let the command run completely, it unlinked all files and you know have an empty directory tree. And git will not help you, because it works by storing its metadata and current state within a .git directory at the root of the working directory. In which you just deleted all files.
So no, unless you made a copy, either manually or by pushing you state to some other place, it's probably gone, but see below. For future reference, here is the correct command to destroy all files ending in png:
find . -name '*.png' -delete
Optionnaly add -type f before the -delete if you may have directories ending in .png, to filter them out.
Okay, what now: it happens that git marks some of its internal state as read-only, which rm honors if you didn't use rm -f and you might be able to recover some data from that. Go to the .git directory at your working directory's root. It will contain a objects directory, and some files may have survived there.
Those files are raw compressed streams, you can see their content using that command:
zlib-flate -uncompress <path_to_the_file
(the zlib-flate command comes from qpdf package on ubuntu)
for me the following worked:
$ git checkout -- name_of_deleted_directory
or
$ git checkout -- path_to_local_delected_directory
In my case, I deleted a directory by mistake and I didn't change any code in that directory but I had changed code in other directories of my git repo.

Get only structure of repo folders without files

I have some repo in perforce, I want to download only structure of folders without files, do you know how can I make this ?
Cheers
To learn about the folders/directories that are in a certain section of your Perforce repository, you can use the p4 dirs command (see http://www.perforce.com/perforce/doc.current/manuals/cmdref/p4_dirs.html).
For example,
p4 dirs //depot/*
will tell you all the top-level directories under //depot. Suppose the list that comes back is:
//depot/main
//depot/r1.0
Then you could subsequently issue:
p4 dirs //depot/main/*
and
p4 dirs //depot/r1.0/*
to learn about the next level of directories, and so forth, until you find no further child directories under the section of the repository that you are searching.
Once you have learned the correct set of directories that correspond to the current contents of your repository in Perforce, you can issue the corresponding mkdir commands to make those directories on your workstation.

Moving the .git directory wihout moving the files

I am using to track changes to some linux system files (/etc/*), I had the .git in /etc
but now I decided to move it to / as I want to track files that are outside /etc (both /etc and / are in the same filesystems...), I did that and tried to re-add the same files with:
git add $(git status | awk '/deleted/ { print "etc/"$3 } ')
But it does not appear to be working as I hoped as now the are two lists one with a list of "new files" and one with a list of "deleted files", if commit now I will lose all the history
for the files....
What would have been the correct steps?
Thanks!
Antonio
Use git subtree (installation instructions if not already installed).
Create a new repository at / and merge it with the existing one in /etc:
$ cd /
$ git init
$ git subtree --prefix etc /etc master
Ther are similar questions on SO:
My Git repository is in the wrong root directory. Can I move it? (../ intead of ./)
Moving a git repository
And there is no way of chaning directory without losing history of files.

svn problem. I can't add it because it's already in another SVN

svn add guess_language/
svn: warning: 'guess_language' is already under version control
Why is this? When I downloaded it, it was under SVN. (I downloaded it from SVN)
How do I release that svn...so that I can turn it into a regular directory?
Remove the .svn directory inside guess_language/ and it's parent (if that also came from another SVN repository). This should allow you to add it to another SVN repository.
This also must be done recursively through guess_language's children. A command which can do this for you (depending on your Linux environment) is:
find . -name '.svn' -type d -exec rm -rf {} \;
(You probably shouldn't just take that for granted, test it with a non-deleting version, i.e find . -name '.svn' -type d and check the only directories listed are the ones you want to remove.)
you can force it to be added to your repository. Use:
svn add --force [folder]
Inside the guess_language directory there will be a hidden directory called .svn. This is how SVN knows that the directory is under version control. Delete that directory and you will then be able to add it to your SVN repository. You will have to do this for every directory, as each directory will have its own .svn directory.
(As an aside, if you look at the contents of a file called entries inside that directory, you can see the url of the SVN repository that the directory originally belonged to)
If you want a "copy" of the directory out of version control, use svn export. The exported directory will contain all the under version control contents of the original one, but will be a "regular directory".
Best regards.
Nuke all the .svn directories.
cd guess_language
find . -name .svn | xargs rm -fr
As the others said, remove the .svn directories to make subversion forget that it's a working copy checkout out from some repository. In the future you can svn export instead of svn checkout to download the files from svn without creating a working copy from them.

Copying the .svn directories from a checkout to a non-checkout to make it a checkout

I have a large application in a production environment that I'm trying to move under version control. So, I created a new repo and imported the app, minus various directories and files that shouldn't be under version control. Now, I need to make the installed copy a checkout (but still retain the extra files). At this point, in a recent version of SVN, I'd simply do a checkout over top the existing directory using the --force option. But sadly, I have an ancient version of SVN, from before when the --force option was added (and can't yet upgrade... long story).
So, I checked out the app to another directory, and want to simply copy all of the .svn directories into the original directory, thus turning the original into a checkout whilst leaving alone the extra files. Now, maybe I'm just having a rough day and missing something that's in plain site, but I can't seem to be able to figure this out. Here are the approaches I've tried so far:
Use rsync: I can't seem to hit the right combination of include and exclude directives to recursively capture all the .svn directories but nothing else.
Use cp: I can't figure out a good way to have it hit all the .svn directories across and down through the whole app.
Use find with -exec cp: I'm running into trouble with the leading part of the pathnames of the found files messing up the destination paths. I can exclude it using -printf '%P', but that doesn't seem to go into the {} replacement for exec.
Use find with xargs to cp: I'm running into trouble with find sending over child directories before sending their parents. Unfortunately, find does not have a --breadth option.
Any thoughts out there?
Other info:
bash 3.0.0.14
rsync 2.6.3 p28
cp 5.2.1
svn 1.3.2
Use tar and find to capture the .svn dirs in a clean checkout, then untar into your app.
cd /tmp/
svn co XXX
cd XXX
find . -name .svn -print0 | tar cf /tmp/XXX.tar --null -T -
cd /to/your/app/
tar xf /tmp/XXX.tar
Edit: switched find/tar command to use NUL terminator for robustness in the face of filenames containing spaces. Original command was:
tar cf /tmp/XXX.tar $(find . -name .svn)
(5) Can't you just make a checkout to a different directory, then copy the extra files to that directory, verify that everything's fine before switching to running the app from the new directory?

Resources