mootools php faith camera linux


Git rm -vs- rm

git rm -vs- rm

If working on a project you removed a file using: rm <file> you may be faced with a message similar to this when using git and issing the command git status :

# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#    deleted:    parsezip.php
#    deleted:    parsezipagent.php

What to do if I deleted my file when it was under git source control?

First, stay calm if git is new to you. To delete this file and have it also be removed from your branch in your local repository, you must again check it out:

git checkout parsezip.php parsezipagent.php

We used the git checkout <file> <file> to get two files for our money.

Your files may be back now. Run git status to see. And if you wish to go ahead and delete them from your repository you need but 13 characters:

$ ^checkout^rm^

And after that if you run git commit the files will be gone, and your working directory will be clean again!

Wait, what?

Using a handy replacement technique that acts upon the previous history item, ^a^b^ , the top hat character separates "a", the previous command's string to replace with "b", the desired replacement. And so now, instead of fixing our accident of rm <file> , we do a one-two punch on the problem with fewer characters than you can shake a stick at.

$ echo hello;
$ ^hello^world^

Note when using the top hat history replacement technique to run a previous command with a string replacement that the final command that will be run is printed to the screen before any output from that command. That's why the output immediately after $ ^hello^world^ is the actual command echo world; which then, in turn, echoes world to end the interaction.

Deal with "changed but not updated" "deleted" files in git

In short, and in the future, try not to delete files using rm <file> if the files are under git source control. Instead, one should git rm <file> so as to not create the git status response in "changed but not updated" where one or more files have been "deleted".

Aw man, i forgot to git rm my files.

There is a great StackOverflow answer regarding "deleted files from 'changed but not updated' in git". The solution:

git ls-files --deleted -xargs -0 git rm

Or another similar solution:

git rm $(git ls-files --deleted)

Last Updated: 2014-08-04 15:47:45
Creative Commons License Jay Johnston is a Zend Certified Engineer in PHP 5 LPI-ID: LPI000102450, Verfication Code: wmnnt56y2k  ... Jay Johnston is certified as LPIC-1 by the Linux Professional Institute