简体   繁体   English

在我的反应应用程序上运行“npm run deploy”后提交对 git 的更改时出现问题

[英]Problems when it comes to committing changes to git after running 'npm run deploy' on my react app

So I have successfully deployed my react project on GitHub pages, there are a lot of useful guides on how to do this.所以我已经成功地在 GitHub 页面上部署了我的 react 项目,有很多关于如何做到这一点的有用指南。 However I am having issues when it comes to updating the project (it is harder to find good guides on this)但是,在更新项目时我遇到了问题(很难找到好的指南)

So lets say I make a change to my project on the code as it exists in folders on my computer.因此,假设我在代码上对我的项目进行了更改,因为它存在于我计算机上的文件夹中。

Then I will run 'npm run deploy'.然后我将运行“npm run deploy”。 After doing this, I can see my changes have been successfully implemented on my online deployed site, so all good.完成此操作后,我可以看到我的更改已在我的在线部署站点上成功实施,一切都很好。

Then I run the following code to push the changes into the repository:然后我运行以下代码将更改推送到存储库中:

git add .

git commit -m "update"

That works fine, but I get an error at the next step:这工作正常,但我在下一步得到一个错误:

git push -u origin master

When I do this I always get the same error message in the terminal:当我这样做时,我总是在终端中收到相同的错误消息:

error: failed to push some refs to 'https://github.com/redacted/redacted.github.io.git'
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.

Can anyone please explain what is happening here, and what this error message means.谁能解释一下这里发生了什么,以及这个错误消息的含义。

In the error message, does 'remote' mean the code as it exists in the GitHub repo, and 'local' mean the code on my computer?在错误消息中,“远程”是指 GitHub 存储库中存在的代码,“本地”是指我计算机上的代码吗? Why does the remote code and local code diverge after running 'npm run deploy'?为什么运行“npm run deploy”后远程代码和本地代码会出现分歧? In future, what is the best way for me to update the repository so that I don't keep running into this problem.将来,对我来说更新存储库的最佳方法是什么,以免我一直遇到这个问题。

If it's important, here are my scripts on the package.json file:如果它很重要,这是我在 package.json 文件上的脚本:

"predeploy": "npm run build",
"deploy": "gh-pages -b master -d build",

hint: Updates were rejected because the remote contains work that you do not [...] have locally.提示:更新被拒绝,因为远程包含您在本地没有的工作 [...]。

There are commits on the remote that you don't have locally.远程上有您在本地没有的提交。 To see them, you can use git diff .要查看它们,您可以使用git diff First, update the local representation of remote references in your repo:首先,在你的仓库中更新远程引用的本地表示:

git fetch

Now that you have an up-to-date local representation of what's on origin/master , you can see the differences with:现在您有了origin/master上内容的最新本地表示,您可以通过以下方式看到差异:

git diff origin/master

Git diff is one of the most important parts of the git tooling, so become acquainted with its syntax. Git diff 是 git 工具最重要的部分之一,因此请熟悉其语法。 This should show you what changes you've missed.这应该向您显示您错过了哪些更改。 you can also pull up the log of origin/master which will show the commit messages, authors, and dates with:您还可以调出origin/master的日志,其中将显示提交消息、作者和日期:

git log origin/master

If this loads up in an editor you don't recognize and the lower left of the screen is a : colon character, type q to quit.如果它在您不认识的编辑器中加载并且屏幕左下角是:冒号字符,请键入q退出。 This program is called less .这个程序叫做less

All that helps you introspect the remote changes that you haven't incorporated locally.所有这些都可以帮助您反省尚未在本地合并的远程更改。 When you're ready to pull them into your own branch, simply issue:当您准备好将它们拉入您自己的分支时,只需发出:

git pull

This will apply missing commits to your local branch.这会将缺失的提交应用到您的本地分支。 If the local commits change the same lines as the remote commits, you'll end up with a git conflict.如果本地提交更改与远程提交相同的行,您将最终遇到 git 冲突。 In this case you'll have to look at the conflicts and decide how to combine the two changes.在这种情况下,您必须查看冲突并决定如何组合这两个更改。 Often, remote changes can be incorporated without causing any conflicts, but of course it depends on what's been changed on both sides.通常,可以合并远程更改而不会引起任何冲突,但这当然取决于双方都进行了哪些更改。

A final note.最后一点。 What you absolutely do not want to do is git push -f .您绝对不想做的是git push -f This will force push your changes to master, replacing its current history - in other words, you'll destroy the remote changes.这将强制将您的更改推送到 master,替换其当前历史记录 - 换句话说,您将破坏远程更改。 Never do this.永远不要这样做。 There's a time and a place for it, and once you get more comfortable with git diff and its behavior as a distributed change control system, you can revisit that advice.它有时间和地点,一旦您对git diff及其作为分布式变更控制系统的行为更加熟悉,您可以重新审视该建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行 npm 运行构建后反应应用程序更改未更新 - React app changes not updaiting after running npm run build 尝试将我的反应应用程序部署到 github 后,“npm run deploy”无法正常工作 - "npm run deploy" not working after trying to deploy my react app to github 在部署到 heroku 并运行 npm 构建后对应用程序进行更改 - Making changes to app after deploy to heroku and running npm build 在运行“create-react-app my-app”后尝试运行“npm start”时出现一堆错误 - Get a bunch of errors when trying to run “npm start” after running “create-react-app my-app” 为什么在运行npm run deploy之后我的存储库会更改? - Why does my repository change after running npm run deploy? 无法在我的 React 应用程序中运行“npm run build”/“npm run deploy”命令 - Can not run 'npm run build' / 'npm run deploy' command in my react app 尝试 npm 运行迁移以部署我的应用程序时 heroku 出错 - Error on heroku when trying to npm run migrate to deploy my app React Redux'npm run deploy'应用无法正常工作 - React Redux 'npm run deploy' app not working npm 运行部署对于反应应用程序无法正常工作 - npm run deploy not working properly for react app 当在 react 中运行 npm test 时,Jest 给了我下面的消息,我要做的就是运行它默认在 App.test.js 中的测试 - When running npm test in react Jest is giving me the message below and All I am trying to do is run the test it comes by default inside App.test.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM