由于git状态中存在已删除的文件,无法推送。

huangapple go评论83阅读模式
英文:

Unable to push due to git status deleted files?

问题

我会直接说。

我的教授指导我们将我们的第一个文本文件推送到Git网站。然后她给了我们一个个人任务,我们将推送另一个文件,但只能使用git add,git commit -m "text"和git push origin master(这是她说的,因为那是我们唯一能用的命令)。每当我使用git status时,下面显示的图像可能会阻碍我推送。有什么建议我如何解决这个问题?

由于git状态中存在已删除的文件,无法推送。

我尝试过git checkout --以及执行建议的命令git restore 。当两者都尝试后,它只生成了另一个命令行,当我们使用git status确认时,它仍然存在。

英文:

I will be straightforward.

My professor guided us at pushing our very first text file to the git website. She then gave us an individual activity where we will push another, but should only use git add., git commit -m "text", and git push origin master (that is what she said because that's all we have to use). Whenever I use git status, the image below shows up which probably hinders my ability to push. Any tips on how I can fix this?

由于git状态中存在已删除的文件,无法推送。

I tried git checkout -- and doing the suggested command which is git restore <file here>. When doing both, it just generated another command line, and when we confirmed it using git status, it is still there.

答案1

得分: 1

当您使用git status时,您会得到自上次提交以来所做的更改,就您的情况而言,它告诉您您所做的更改是删除了文件../activities/aboutme.txt,如果您要修改或删除任何其他文件,那么在再次运行git status时会显示出来。

如果您想保留该文件,只需运行git restore ../activities/aboutme.txt,如果您想提交删除该文件的更改,则运行git add ../activities/aboutme.txt,或者如果您只想添加所有所做的更改,则运行git add .,尽管您需要移动到根目录,因为根据图片看起来您不在项目的根目录上。

希望这对您有所帮助。

英文:

When you use git status you get the changes you've made since the last commit, in your case it is telling you that the changes you made are that you deleted the file file ../activities/aboutme.txt, if you were to modify or delete any other file then that would show up if you run git status again.

If you want to keep that file you just need to run git restore ../activities/aboutme.txt, if you want to commit that you deleted the file then run git add ../activities/aboutme.txt or if you just want to add all the changes you've made run git add ., although you would have to move to the root directory, since on the picture it looks like you are not on the root directory of your project.

Hope this helps.

答案2

得分: 1

好的,以下是已翻译的部分:

"好吧,git 没有问题!我想你之前有一个名为 'aboutme.txt' 的文件,并且你已经将其推送到你的仓库,现在你已经删除了那个文件,这就是为什么 'git status' 给出了这个信息。如果你想恢复已删除的文件,应按以下顺序运行这两个命令:

git reset HEAD
git checkout -- .

但如果你想提交已删除的文件,只需使用以下命令:

git add .
git commit -m "Text file deleted"
git push"

英文:

Well, there's nothing wrong with git! I suppose you had a file named aboutme.txt and you've pushed it to your repository before and now you've deleted that file and that's why git status gives you that thing. If you want to restore the deleted file you should run these two commands in order:

git reset HEAD
git checkout -- .

But if you want to commit the deleted file just use these commands:

git add .
git commit -m &quot;Text file deleted&quot;
git push 

答案3

得分: 0

看起来你使用了git rm命令删除了你的文件,但由于它显示在sit状态中,没有提交它。请使用git commit命令提交它。它将从你的跟踪器中删除。

英文:

It seems you deleted your file by using git rm command and didn't commit it due to that showing on sit status. Please commit it by using git commit command. It will be remove from your tracker

huangapple
  • 本文由 发表于 2023年8月9日 13:12:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864756-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定