Wednesday, September 15, 2010

Git rm may cause insanity

Ran across this today, and wanted to help others avoid the same fate. If you use git rm to remove the last file in a directory, it will remove the directory as well. If you are in that directory, odd things can happen that will potentially drive you insane.

Let's create a git repository with a folder that has a single file in it:
$ cd /tmp
$ mkdir foo
$ cd foo/
$ git init
Initialized empty Git repository in /private/tmp/foo/.git/
$ mkdir bar
$ cd bar/
$ echo 'hello' > splat.txt
$ git add splat.txt
$ git ci -m 'adding a text file'
[master (root-commit) 069f11b] adding a text file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 bar/splat.txt

So I now have a git repository and placed the file bar/splat.txt under revision control. Now if I do:
$ git rm splat.txt
rm 'bar/splat.txt'
This will not only remove splat.txt, but it will remove the whole bar directory. I say this will drive you insane, because if you try to move or copy a file into your current directory, you'll get an error that will probably catch you off guard. Like:
$ cp ~/.gitignore .
cp: ./.gitignore: No such file or directory
There is a file called .gitignore in my home directory, it's just that my current directory no longer exists. It took me about five minutes to realize what was going on... and I was starting to wonder if I knew how to use the cp command.

The reason I ran into this is that I was rearranging my .vim folder to use pathogen. I keep all of my dot files under source control and stumbled upon this while clearing out my vim autoload folder.

8 comments:

Lawerence B. Vestal said...

children and can you may realize many various creditors you will take produce use of. By practice motivated for making each and every realizing comprehensive hot and friendly, quickly, respectful, at the side of helpful, most people is auto title loans costa mesa alright to assist you invest in your responsibility. Have a look at nearly any us of America ALL day cash upgrades position presently in addition to we tend to tend to shall show the merchandise for yourself.

marko said...

You get to some degree lower rate of enthusiasm and more reimbursement periods. In both cases, the hobby is connected level on the advance sum and is separated into equivalent regularly scheduled payments. auto title loans online

Samuel Moreland said...

You must be mindful that any kind of secured advance obliges advantages for serve as an insurance against the credit sum.payday loans

marko said...

In the event the possibility become 1 will method the proprietor on the pre-foreclosure phase, is it doesn't time among how the discover is actually released from the loan company for the seller plus the residence is actually foreclosed.payday loans

marko said...

On the off chance that you are encountering trouble paying back again the advance, also there is the chance that the auto may wind up being repossessed, so make certain you have an arrangement in position for reimbursing the credit before you start. cash advance loans in fresno ca

marko said...

Not at all like little business advances, there are no printed material bothers or any kind of weight for extra expenses. Many little entrepreneurs have profited from this loan program. Cash Advance

MUSA77 said...

On the off chance that you oblige cash then get unnerving Visas and pay them on time to deliver your credit. Pay more than the base hole and utilization them to pay bills so you can pay what you have to pay while making your credit. https://www.usacheckcashingstore.com/san-diego

Ami Khan said...

In spite of the way that the title bank won't approach you what the money is for, oversee yourself to not taking out an auto title progress pointlessly. With result expected in a month, these transient advances are best used for emergency costs. Take out exactly what you truly oblige so the portion is to a lesser degree a weight toward the end of the month term period.Payday Loans