首页 > 解决方案 > 由于结帐问题,由于 git 无法添加文件

问题描述

git add .当我在 Git bash 会话中发出命令“”时,我无法将任何文件添加到 git 。
它显示错误:

'EG' does not have a commit checked out. 
 fatal : adding files failed.

我现在无法在 Git 中进行任何操作。

我尝试了所有git checkout命令,删除了分支。
我什至从我的系统中删除了 git bash。

试图在 Git GUI 中搜索提交,但我也一无所获。
做了这一切,但没有成功。请帮我。

附上我遵循的步骤的图像和我得到的错误

git错误

标签: gitmavengithub

解决方案


嗨,让我告诉你如何使用 git 推送内容的基本步骤。只需检查您是否遵循所有这些。

如果您有一个新项目并且没有初始化 git,那么请执行以下操作:-

git init

然后,每当您在项目文件夹中进行一些更改并保存时,只需返回 git 并执行以下操作:-

git status

如果它以红色显示某些文件名,则表示这些文件已更改,现在您需要暂存要提交的更改。

因此,如果您想暂存单个文件,请复制 bash 窗口中显示的文件路径并执行

git add <file name>

否则,如果您想暂存所有更改,请执行

git add .

下一步是提交分阶段的更改,只需编写:-

git commit -m "<your commit message here>"

暂存所有文件并提交它们的一种快捷方法是

git commit -am "<your commit message here>"

提交文件后,只需执行

git push

一些有用的附加命令:-

git branch --- to know the current branch you are on
git checkout <branchname>  --- to switch to some other branch
git checkout -b <branchname>  --- to create a new branch
git gc --prune=now  ---- to clear all the references

我希望这有帮助


推荐阅读