GIT:在您的根文件夹中使用 CRA 应用程序,我如何才能正确推送到 git?

GIT: with CRA app in your rootfolder, how can I push to git correctly?

我对 git 很陌生。这可能是个愚蠢的问题,但我真的不知道如何解决这个问题。我一直在努力寻找答案,但我找不到...

我正在尝试使用 React.js 和 Node.js 创建我的项目。我创建了 sever.js 和从 'npx create-react-app client' 创建的客户端文件夹。 当我第一次推送到 git 时,我收到了这条错误消息。

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs
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.

当我强制推送它时,它刚刚通过,我发现我的客户端文件夹根本没有推送到 git,它在回购中是空的。另外,我注意到客户端文件夹中有 .git 文件夹。(不知道 cra 应用程序附带 .git 文件)

在客户端文件夹中,我在命令行中输入(我用谷歌搜索,发现该命令将撤消。git init)

rm -rf .git

在此之后,我没有收到错误消息,但我仍然无法将客户端文件夹推送到 git,该文件夹在存储库中仍然是空的。

此外,repo 中客户端文件夹的图像与其他文件夹不同。文件夹中有一个箭头,另一个文件夹中没有箭头。 enter image description here

client 文件夹是 cra app,src 文件夹有服务器端代码。

如何才能将我的代码正确推送到 git??

您需要先删除 client 文件夹的 gitlink (special entry recording the tree SHA1 of the

git rm --cached client # no trailing /: not client/, just client

然后你可以(因为你已经删除了 client/.git 子文件夹),添加客户端(git add client),提交并推送。