In this post, I’ll be dealing with something really basic and is something that most people using git should be knowing about. Nevertheless, I too had been using git for a long time and it’s not every day that you have to come across committing deleted files. That was the case today and I was rather stuck for a while. As always, google helped me out and what I learned today has found it’s way into my blog. Coming to the point, this post will deal with how you commit deleted files. Only once you commit can you push these changes and hence this is just as important as anything else. I assume that you know how to add, commit and push changes to files in your repo. Here’s mine before pushing changes :
Once you have deleted the files locally(probably using the rm command or using graphical tools), you need to now remove those files from git. For that use the command $ git rm <filename> So, if there are multiple files that you have removed locally and need to be committed, that would mean removing all those individually, one by one from the git. Instead of that you can run this simple command to do the trick $ git rm $(git ls -files –deleted) Basically the git -ls -files –deleted shows the list of files that were removed locally but git still keeps track of. You remove all of these at once from git now, using the “git rm” command. Here’s a screenshot of my terminal screen.
That then shows how the files were deleted and once you’ve done that you just need to commit and push the changes to the repo. Here’s my repo after committing the deleted files. You know the rest, just push the changes now.