remove git_如何使用“ git Remove”而不删除文件

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

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值