git常用命令整理(Git删除文件)

0、没有add的文件, 手动删除就可以了。

touch install/wiki.sql
# 只能手动删除, 不能使用git rm
git rm install/wiki.sql
fatal: pathspec 'install/wiki.sql' did not match any files
# 手动删除
rm -f db.ini

1、add但是没有commit的文件, 执行git rm就可以了

git rm install/wiki.sql

或者强制删除

git rm -f install/wiki.sql

2、提交后的文件, git rm后需要提交删除

# git rm
git rm install/wiki.sql
rm 'install/wiki.sql'

# 查看状态deleted
git status
On branch bugfix_rprank_0510
Your branch is ahead of 'origin/bugfix_rprank_0510' by 1 commit.
  (use "git push" to publish your local commits)
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	deleted:    install/wiki.sql

# 提交删除
git commit -m 'remove wiki.sql' install/wiki.sql
或者
git commit -m 'remove wiki.sql'

不能使用匹配,如下异常提示Changes not staged for commit
git commit -m 'remove wiki.sql' install/*
On branch bugfix_rprank_0510
Your branch is ahead of 'origin/bugfix_rprank_0510' by 1 commit.
  (use "git push" to publish your local commits)
Changes not staged for commit:
	deleted:    install/wiki.sql

no changes added to commit
注:这一点跟新增/修改文件提交不一样,原因待分析⌛️。

发表评论

电子邮件地址不会被公开。 必填项已用*标注