Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add all removed files to a commit with git

Tags:

git

I have made a round of changes to a branch and have 10 modified files and 10 files I have deleted.

If I run git add . this will only add the modified files to my commit. I want to remove the deleted files from the remote repo as well as add my modified files.

I can use git rm filename, but since I have so many files to remove I was wondering if there was a way to do an 'all'.

I Googled and found git rm -r * but this doesn't seem to work.

Is there a command that will allow me to do this?

like image 497
MeltingDog Avatar asked Jan 06 '17 00:01

MeltingDog


People also ask

How do you add all files to git commit?

Enter git add --all at the command line prompt in your local project directory to add the files or changes to the repository. Enter git status to see the changes to be committed. Enter git commit -m '<commit_message>' at the command line to commit new files/changes to the local repository.

Is there a way to git add all files?

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

If you want to stage all your changed and deleted files and commit in one-line:

git commit -am "changing and deleting files" 

Note that this command won't add new files as Git is about tracking changes. It relies on you to tell it which files are important enough to track. If you have some or you just want to stage the changes before you commit, you will have to add your files manually or use wildcard:

  • git add -A stages All (include new files, modified and deleted)
  • git add . stages new and modified, without deleted
  • git add -u stages modified and deleted, without new

then commit:

git commit -m "..." 
like image 174
ET-CS Avatar answered Sep 23 '22 00:09

ET-CS


Try this:

git add -u to stage all your changes including deleted/updated files.

Then just run git commit -m 'your commit message' to commit.

like image 29
Alex Pan Avatar answered Sep 25 '22 00:09

Alex Pan