如何从git repo中删除文件? [英] How can I delete a file from git repo?

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

问题描述

我添加了一个名为file1.txt的文件到git repo。之后,我承诺,添加一个名为 dir1 dir2 的几个目录,并将它们提交给git repo。

I have added a file named "file1.txt" to git repo. After that I committed it, added a couple directories called dir1 and dir2, and committed them to git repo.

现在的回购有file1.txt dir1 dir2

如何删除file1.txt而不会影响其他人如 dir1 dir2

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

推荐答案

使用 git rm

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 repo中删除文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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