remove git
If you use Git, you're probably adding files all the time as you develop your project out further and further. Sometimes though, you might need to actually remove a file from the Git repository but not not from your local files. For example, say you forgot to add a file to .gitignore
but you don't want to remove it from your local development environment. This could be from a mistake or you didn't realize that a new package or something created a bunch of nasty log files you don't want in the repo. Either way, this is actually very easy to do.
如果使用Git ,那么随着项目的不断发展,可能一直都在添加文件。 但是有时,您实际上可能需要从Git存储库中删除文件,而不是从本地文件中删除文件。 例如,假设您忘记将文件添加到.gitignore
但又不想将其从本地开发环境中删除。 这可能是由于错误造成的,或者您没有意识到新的程序包或某些东西创建了一些您不想在回购中使用的讨厌的日志文件。 无论哪种方式,这实际上都是很容易做到的。
使用Git删除单个文件而不删除它 ( Removing a single file with Git without deleting it )
This method will remove a single file from your Git repository without deleting the file from your local environment. Then when you run git push
, the files will be removed in the remote repo.
此方法将从您的Git存储库中删除一个文件,而不会从本地环境中删除该文件。 然后,当您运行git push
,文件将在远程仓库中删除。
git rm --cached filexample.txt
使用Git删除多个文件而不删除它们 ( Removing multiple files with Git without deleting them )
In a similar fashion, you can do this for multiple files at one time.
以类似的方式,您可以一次对多个文件执行此操作。
git rm --cached file1.txt file2.txt file3.txt
删除整个目录而不删除文件 ( Removing an entire directory without deleting the files )
This also works recursively for folders so long that you add the -r
flag to the command. Here's an example:
只要您将-r
标志添加到命令中,这也可以递归地用于文件夹。 这是一个例子:
git rm -r --cached folder
翻译自: https://scotch.io/tutorials/how-to-use-git-remove-without-deleting-the-files
remove git