【git】本地仓库删除文件,需要同步远程仓库

  1. 打开 git bash ,输入 git rm -r --cached filename ,其中filename为文件名。如果只是删除仓库文件而不删除工作区文件,注意一定要加上 --cached 否则会把工作区文件也删除
  2. 然后 git commit -m 'delete'git push 即可提交到远程仓库,这时远程仓库文件也更新。

如果需要通过 .gitignore 文件来屏蔽文件,如 .idea ,可以如下操作:

touch .gitignore              创建.gitignore文件,然后在文件中输入需要屏蔽的文件或文件夹

git rm -r --cached .idea		删除远程仓库中的文件

git add .					将.gitignore文件加入暂存区,注意不要使用git add *

git commit -m 'change'		提交到本地仓库

git push origin master		提交到远程仓库

git add .git add * 的区别:git add . 会把本地所有untrack的文件都加入暂存区,并且会根据 .gitignore 做过滤;但是 git add * 会忽略 .gitignore 把任何文件都加入

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐