git 从 github 上的 master 中删除文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9778604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:38:00  来源:igfitidea点击:

Remove files from master at github

gitubuntugithub

提问by danielsvane

First time playing with git, and I accidentally added all hidden files with my commit. Now that I have set up my .gitignore, and committed my changes, all the files ending with "~" are still there.

第一次玩 git,我不小心在提交时添加了所有隐藏文件。现在我已经设置了我的 .gitignore 并提交了我的更改,所有以“~”结尾的文件仍然存在。

How do I commit my local files, and remove those from master that are not supposed to be there any more?

我如何提交我的本地文件,并从 master 中删除那些不应该再存在的文件?

回答by Shocker

Use git rm --cached FILENAMEto delete it from the repository but keep the file physically and git add FILENAMEto add a file to your repository. You will need to commit both of these changes with git commit

使用git rm --cached FILENAME从资源库中删除,但保持文件的物理和git add FILENAME将文件添加到您的存储库。您将需要提交这两个更改git commit

回答by user3280979

Here is a DOS batch file that can help:

SET count=1
FOR /F "tokens=*" %%G IN ('dir /s /b *.dll') DO (call :subroutine "%%G")
FOR /F "tokens=*" %%G IN ('dir /s /b *.pdb') DO (call :subroutine "%%G")
FOR /F "tokens=*" %%G IN ('dir /s /b *.txt') DO (call :subroutine "%%G")
FOR /F "tokens=*" %%G IN ('dir /s /b *.cache') DO (call :subroutine "%%G")
FOR /F "tokens=*" %%G IN ('dir /s /b *.force') DO (call :subroutine "%%G")
GOTO :eof

 :subroutine
  git rm --cached %1
  set /a count+=1
  GOTO :eof