Aso Strife
Aso Strife

Reputation: 1129

Git, commit and push changes with deleted file not working

Usually when I have to commit my daily work I use:

git add * 
git commit -m "my commit message"
git push origin master

This commands are very base. But I've notice that deleted file are not deleted from my remote repo. In fact if I delete a generic file "example.txt" (on my local folder)after push changes on Github the file still remain.

Tecnically with git add * the deleted files should be recognized, or not? How can I remove from my remote repo the deleted file?

Thanks

Upvotes: 9

Views: 13226

Answers (3)

instantepiphany
instantepiphany

Reputation: 179

git add does not by default record file deletions. Passing the --all flag will tell it to also look for deleted files.

As Tim Biegeleisen suggested, it is worth combining the use of git status to see the changes in your working directory, and then using git add <filename> to add them one by one. This way you have more visibility and control over what you add to the staging area. You can also use git add <directory> to add a whole directory at once, or git add -i which will ask git to walk you through each file change and let you choose to stage it or ignore it.

Upvotes: 6

Not exactly, from this web

Use git rm

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​

Description:

Remove files from the index, or from the working tree and the index. git 
rm will not remove a file from just your working directory. (There is no 
option to remove a file only from the working tree and yet keep it in the 
index; use /bin/rm if you want to do that.) The files being removed have 
to be identical to the tip of the branch, and no updates to their 
contents can be staged in the index, though that default behavior can be 
overridden with the -f option. When --cached is given, the staged content 
has to match either the tip of the branch or the file on disk, allowing 
the file to be removed from just the index.

Upvotes: 2

Arpit Solanki
Arpit Solanki

Reputation: 9931

git add * does not track the deleted files it only includes modified or new added files. You have to use

$ git add . --all

to track all files (deleted files included)

Refs: docs

Upvotes: 7

Related Questions