Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add * does not add deleted files

Tags:

git

github

I have a local directory in which I have initialized git. I have added all files of that directory in git using:

git add *

Now if I delete a file manually from my local directory, I want to get it deleted from github too. I have tried

git add -A *

But it does not work. Everytime I have to delete it manually from github too.

like image 766
Nur Imtiazul Haque Avatar asked Apr 04 '17 05:04

Nur Imtiazul Haque


People also ask

Does git add add deleted files?

Add All Files using Git Add. 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.

Does git ignore delete files?

gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file. You can omit the --cached option if you want to delete the file from both the repository and your local file system.

What is difference git add * git add?

Hi@akhtar, The difference lies in which files get added. git add -A command will add all modified and untracked files in the entire repository. Whereas git add . will only add modified and untracked files in the current directory and any sub-directories.

Does git keep track of deleted files?

Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.


2 Answers

The problem is that the glob (*) is expanded by your shell, not git, and the shell does not know anything about the files that you have already deleted. git add -A without any more arguments would add all the files, including deleted files. git add . will also do this in the current git version. You could also use git rm --cached <file> for individual files as suggested in other answers.

It's usually easier to just use git rm to remove the files, as this will both remove the file AND stage the removal.

like image 158
1615903 Avatar answered Oct 12 '22 13:10

1615903


If you want to delete a file from your index you should use

git rm filename

Documentation can be found here: https://git-scm.com/docs/git-rm

An important note for this command is:

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.)

Let me know if it works!

like image 34
rmeertens Avatar answered Oct 12 '22 12:10

rmeertens