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

混江龙づ霸主 提交于 2020-06-26 14:41:27

问题


I am quite new to git. it might be a stupid question but I really don't know how to solve this problem.. I have been trying to find the answer but I couldn't...

I was trying to create my project using React.js and Node.js. I created my sever.js and client folder that is created from 'npx create-react-app client'. when I first pushed to git, I had this error message.

 ! [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.

when I force-pushed it, it just went through and I found my client folder is not pushed to git at all, it is just empty in the repo. also, I noticed there was .git folder in client folder.(did not know cra app comes with .git file)

in client folder, I typed on command line (I googled and i found this command will undo .git init)

rm -rf .git

after this, I dont get the error message but still I cannot push client folder to git, the folder is still empty in the repo.

Also, the image of client folder in the repo is different then others. there is an arrow in the folder, the other folder does not have an arror in it. enter image description here

client folder is cra app and src folder has server side codes.

how can I push my code to git correctly??


回答1:


You need first to remove the gitlink (special entry recording the tree SHA1 of the nested git repository for the client folder)

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

Then you can (since you have removed the client/.git subfolder), add client (git add client), commit and push.



来源:https://stackoverflow.com/questions/62255128/git-with-cra-app-in-your-rootfolder-how-can-i-push-to-git-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!