Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git, commit and push changes with deleted file not working

Tags:

git

github

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

like image 345
Aso Strife Avatar asked Aug 13 '17 14:08

Aso Strife


People also ask

Do I add deleted files to git commit?

To add a single file to the commit that you've deleted, you can do git add what/the/path/to/the/file/used/to/be . This is helpful when you have one or two deletions to add, but doesn't add a batch of deletions in one command.

What happens when we delete a file and push new commits to git repository?

It means that the file was removed from the filesystem but it was not deleted from the index just yet. In order for the changes to be effective, you will have to commit your changes and push them to your remote repository.

Will git push delete files?

Using git rm <deleted-filename> and git add <deleted-filename>. Your branch is up-to-date with 'origin/master'. It will stage the deleted file, and followed by git commit and git push will remove the file from the repository.


2 Answers

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.

like image 55
instantepiphany Avatar answered Oct 18 '22 07:10

instantepiphany


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

like image 43
Arpit Solanki Avatar answered Oct 18 '22 07:10

Arpit Solanki