Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - rm equivalent for "add ."?

If you're using Git from the command line, is there a way to delete in one fell swoop all the files to be deleted in the Changed but not updated list? Rather than doing manual removes using wildcards.

like image 596
Steve Avatar asked Apr 19 '10 15:04

Steve


People also ask

What is git add rm?

git rm is used to remove a file from a Git repository. It is a convenience method that combines the effect of the default shell rm command with git add .

How do I clean up git add?

To undo git add before a commit, run git reset <file> or git reset to unstage all changes.

What is git add command?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .

Is there a git add all command?

The easiest way to add all files to your Git repository is to use the “git add” command followed by the “-A” option for “all”. In this case, the new (or untracked), deleted and modified files will be added to your Git staging area. We also say that they will be staged.


2 Answers

The following should stage all files, whether deleted or not, in the index:

git add -A
like image 169
Sujoy Gupta Avatar answered Sep 22 '22 16:09

Sujoy Gupta


Well, the files listed under Changed but not updated are already in the index. You can discard their changes by using git checkout .
To remove file that are new, but have not been added to the index you can use git clean.
But for deleting files that are modified and in the index ... well there is no easy solution, you probably have to use a combination of git rm and git ls-files.

EDIT:
git ls-files -m should list the files you are looking for. Combine it with git rm and you are done:

git-ls files -m | xargs git rm // NOT TESTED

EDIT:
I probably misunderstood a part of your question. My solution will delete all files listed under Changed but not updated. If you want to remove the files listed as deleted, you have to use git diff as Charles Bailey shows in his answer.

like image 44
tanascius Avatar answered Sep 24 '22 16:09

tanascius