tupini07
tupini07

Reputation: 558

Is there a command like "git add ." but for git rm?

In Git, whenever I need to stage files I can use

git add .

to add all the files that have modified since my last commit. However when I remove one file I have to remove it one by one by doing

git rm 'filename'

And git rm . simply deletes everything that was being tracked by git.

I was wondering if there is a command similar to git add . but for git rm.

Thanks :)

EDIT:

I think I didn't explain myself correctly. Lets say I have some files in my git directory which are being tracked by git and lets call them file1, file2, file3. If I where to remove (rm command) file1 and file3 then git status will tell me that those files where deleted and to execute git rm "filename" to update what will be committed. So the question is, is there a way to add this removing action of both files with one single command?

If I where to modify/add different files then I could simply run git add . and all modifications/additions will be added to the staging area so as to be committed.

Upvotes: 0

Views: 1612

Answers (3)

tupini07
tupini07

Reputation: 558

For anyone who is interest I found a much cleaner solution to this.

The default when you execute git add . is:

git add --ignore-removal <paths>

This default behavior is exactly the root of this question (how to add the removals and changes to the staging area using just one instruction). This can be easily done with the command:

git add --all .

which does not ignore removal.

Hope it helps somebody as it helped me :)

Upvotes: 0

krngrvr09
krngrvr09

Reputation: 123

You might want to checkout the answere here

The command is basically this: git rm $(git ls-files --deleted)

Upvotes: 1

Magnus B&#228;ck
Magnus B&#228;ck

Reputation: 11571

Use git add -u/git add --update or git add -A/git add --all. The former will stage modified and deleted files while the latter also stages new (untracked) files.

Upvotes: 2

Related Questions