如何从Git存储库中删除文件? [英] How can I delete a file from a Git repository?

查看:101
本文介绍了如何从Git存储库中删除文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将名为"file1.txt"的文件添加到Git存储库.之后,我提交了它,添加了两个名为dir1dir2的目录,并将它们提交到Git存储库.

I have added a file named "file1.txt" to a Git repository. After that, I committed it, added a couple of directories called dir1 and dir2, and committed them to the Git repository.

现在,当前存储库具有"file1.txt"dir1dir2.如何删除"file1.txt"而不影响其他人,例如dir1dir2?

Now the current repository has "file1.txt", dir1, and dir2. How can I delete "file1.txt" without affecting others, like dir1 and dir2?

推荐答案

使用 git rm .

如果要从Git存储库和文件系统中删除文件,请使用:

If you want to remove the file from the Git repository and the filesystem, use:

git rm file1.txt
git commit -m "remove file1.txt"

但是,如果您只想从Git存储库中删除文件而不是从文件系统中删除,请使用:

But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:

git rm --cached file1.txt
git commit -m "remove file1.txt"

然后将更改推送到远程仓库

And to push changes to remote repo

git push origin branch_name

这篇关于如何从Git存储库中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆