在git仓库中包括一个带有自己的git文件夹的React应用 [英] Include a React app with its own git folder in git repository

查看:101
本文介绍了在git仓库中包括一个带有自己的git文件夹的React应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个要包含在同一个存储库中的应用程序.Express后端和React前端.React前端是使用 npx create-react-app 创建的.以这种方式创建一个React应用程序还会在我的React应用程序的文件夹中创建一个 .git 文件夹和一个 .gitignore 文件.在要包含的父文件夹上运行 git init 后,剩下的存储库包含两个 .git 文件夹:

I have two applications I want to include as part of the same repository. An Express backend and a React frontend. The React frontend was created using npx create-react-app. Creating a React app in this way also creates a .git folder and a .gitignore file in the folder of my React app. After running git init on the parent folder of what I want to include I am left with a repository that contains two .git folders:

.git
.gitignore
README.md
react-frontend
    .git
    .gitignore
    README.md
express-backend

尝试使用 git add将文件添加到存储库后. git向我警告有关第二个 .git 文件夹:

After attempting to add files to the repository with git add . git warns me about the second .git folder:

hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> youtube-dl-react-frontend
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached youtube-dl-react-frontend
hint:
hint: See "git help submodule" for more information.

我不确定该怎么做.什么是子模块,真的是我想用来包含我的React应用程序的子模块吗?还是应该从React文件夹中删除 .git 文件夹?还是我应该在这里做些不同的事情?

I am not sure what to do here. What is a submodule and is it really what I want to use to include my React app? Or should I just delete the .git folder from the React folder? Or is there something different I should be doing here?

我也尝试提交,然后运行 git push -u origin master 来查看是否可以推送更改,但是我无法:

I also tried commiting, then running git push -u origin master to see if I would be able to push my changes, but I was unable to:

error: failed to push some refs to 'my project url'
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文件夹包含git配置文件和提交以及git存储库中的所有更改,请删除.git为您做出反应然后使用的文件夹 Git初始化 Git远程添加来源(回购网址) Git add. Git commit -m您的消息" Git push -u原始主机

A git folder contains git config files and commits and all changes in git repository if you want to make your project directory work with your own git repository delete the .git folder that react made for you and then use Git init Git remote add origin (repo url) Git add . Git commit -m "your message" Git push -u origin master

这篇关于在git仓库中包括一个带有自己的git文件夹的React应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆