如果文件不再存在,如何从 GIT 中删除该文件

How to remove a file from GIT if it doen't exist any more

我第一次尝试使用 git 和 git-hub;

有一个文件我想更改它的名称所以我只是更改它并在我推送它时提交但它说:

[rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/MyUserName/MyProjectName.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

所以我只是添加了 -f 来强制,但是它创建了另一个目录来保存文件的旧名称,所以我删除了它但是每次我执行 push 命令时它都会做同样的事情

我怎样才能永远摆脱这个旧文件 谢谢。

在推送本地更改之前,您需要拉取最新版本的 GitHub 存储库。

git pull

在此之后对本地存储库进行您希望进行的更改(在这种情况下更改文件名)

然后:-

git commit -am "Message"
git push