git add *不添加已删除的文件 [英] git add * does not add deleted files

查看:690
本文介绍了git add *不添加已删除的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个本地目录,其中已初始化git.我已经使用以下命令在git中添加了该目录的所有文件:

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

git add *

现在,如果我从本地目录中手动删除文件,我也想从github中删除它.我尝试过

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 *

但是它不起作用.每次我也必须从github上手动删除它时.

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

推荐答案

问题是glob(*)由您的shell(而不是git)扩展,并且shell对您所拥有的文件一无所知已经删除. git add -A如果没有其他任何参数,则会添加所有文件,包括已删除的文件. git add .也将在当前git版本中执行此操作.您还可以按照其他答案中的建议对单个文件使用git rm --cached <file>.

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.

使用git rm删除文件通常会更容易,因为这将删除文件并进行删除.

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

这篇关于git add *不添加已删除的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆