git删除远程分支文件并保留本地文件

  • git rm --cached 文件全路径
  • git commit -m ‘备注’
  • git push
hj(master)
$ git rm --cached app/src/main/java/com/test/takepicture/Test02.java
rm 'app/src/main/java/com/test/takepicture/Test02.java'

hj@DESKTOP-TSCP95M MINGW64 /e/as_workspace/take_picture1 (master)
$ git commit -m '测试只删除远程远程分支,不删除本地分支'                                                                [master a610419] 测试只删除远程远程分支,不删除本地分支
 1 file changed, 5 deletions(-)
 delete mode 100644 app/src/main/java/com/test/takepicture/Test02.java

hj@DESKTOP-TSCP95M MINGW64 /e/as_workspace/take_picture1 (master)
$ git push                                                                                                              Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 8 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 746 bytes | 746.00 KiB/s, done.
Total 9 (delta 3), reused 5 (delta 0)
To https://git.dev.tencent.com/dev_hj/take_picture.git
   b76f98b..a610419  master -> master

提交后,本地版本对应的文件会变成红色
在这里插入图片描述

场景:

上传了自动生成的代码,理论上不应该上传的;删除远程分支文件并保留本地文件后,将本地的该文件添加到ignore中就ok了;下次就不会被提交上去了

你可能感兴趣的:(git)