"git restore –staged" 返回错误 "无法解析 HEAD"

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

"git restore --staged" returns an error "could not resolve HEAD"

问题

我使用git init命令在本地创建了一个Git存储库。

然后我错误地通过输入git add .将所有文件添加到了暂存区,但我想取消暂存一些我不想提交的文件。

但当我输入git restore --staged <文件/文件夹名称>时,它显示如下内容:

致命错误: 无法解析HEAD

我弄清楚了这是因为我的主分支main尚未有任何提交。那么,在我可以提交之前,有可能将某些文件排除在暂存之外吗?如果可以,我该如何实现呢?

英文:

I have created a Git repository locally by using the command git init.

Then mistakenly added all files for staging by entering git add .
But I want to unstage some files which I don't want to commit.

But when I enter git restore --staged &lt;file/folder name&gt;, it states the following:

fatal: could not resolve HEAD

I figured out this occurred due to my branch main having no commits yet. So, is it possible to exclude some files from staging before I can commit? If so, how can I achieve it?

答案1

得分: 3

尝试使用 git reset 以将所有文件从暂存区移除,或者使用 git reset /path/to/file 来操作特定文件。

英文:

Try git reset to remove all files from stage or git reset /path/to/file

huangapple
  • 本文由 发表于 2023年4月16日 23:38:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028701.html
匿名

发表评论

匿名网友

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

确定