为什么在部署 React 项目时,终端命令 'git add .'、git commit...' 和 'git push...' 被列为可选?

Why are terminal commands 'git add .', git commit...' and 'git push...' listed as optional when deploying React project?

抱歉,我对git还是有点困惑,虽然我正在努力自学和提高。

我最近成功部署了一个 React 网站到 GitHub 页面,按照经常推荐的步骤安装 gh-pages 到项目,添加主页 属性 到 package.json 文件,将脚本添加到 package.json 文件上的脚本属性,运行 'npm run deploy' 等等。它运行良好,现在项目的构建已添加到我的存储库 (here), and I can view the actual project online (here)。

但是,我遇到的问题是:大多数关于部署 React 应用程序的指南还提到了以下步骤: 在终端类型中:

git 添加 .

git commit -m "commit"

git push origin master

这些最后的步骤通常被列为可选。没有我执行这些步骤,一切都很好:我的代码已添加到存储库,我的网站已在线部署,那么 这些步骤究竟做了什么?为什么他们被认为是可选的?最佳做法是什么?

这些命令对我来说不是可选的 - 当只使用命令行 Git 客户端时,这些命令完成推送代码的交互(即,在你编辑它之后,只存在于你自己的本地PC) 到 Git 存储库服务器。

Everything worked fine without me doing these steps: my code was added to the repository, and my website is deployed online

我可以看到以下可能性:

  • 您正在使用另一个 Git 客户端并且推送是在那里完成的;
  • 您正在使用 Git 工具(例如纯粹在 GitHub 网站上进行编辑),在您不知情的情况下发生了推送;
  • 您在没有意识到的情况下执行了终端命令;

了解更多关于 Git 的常见资源是官方 Git SCM 网站上的 Git 书籍:https://git-scm.com/book/en/v2