12

我用 AngularJS 创建了一个静态站点,现在想将它作为 Github 页面上传。我已按照此处的所有说明进行操作

https://help.github.com/articles/creating-project-pages-manually

我可以创建一个名为的新分支gh-pagesgit push origin gh-pages我的所有内容都很好。当我去我的仓库时,我看到了新的gh-pages分支,里面有所有的文件,就像这样

https://github.com/siddhion/maxmythic_angular/tree/gh-pages

问题是当我尝试在http://siddhion.github.io/maxmythic_angular/查看我的网站时,我只得到一个 404 页面。index.html我认为问题在于我的顶级目录中没有我的。它实际上位于app目录中。我的目录结构看起来像它的样子,因为我是通过 Yeoman 创建的。我假设我需要顶层的所有文件。或者也许我在这个假设上错了?

如何让我的 AngularJS 静态站点正确显示?

更新

我按照斯蒂芬提供的步骤进行操作。我到了第 3 步,但出现错误:

$ git subtree push --prefix dist origin gh-pages
git push using:  origin gh-pages
To git@github.com:siddhion/maxmythic_angular.git
 ! [rejected]        5db3233d7c0822eedc5500409ce6a2d4b73ad427 -> gh-pages (non-fast-forward)
error: failed to push some refs to 'git@github.com:siddhion/maxmythic_angular.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge 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 pull origin master
From github.com:siddhion/maxmythic_angular
 * branch            master     -> FETCH_HEAD
Already up-to-date.

然后git subtree push --prefix dist origin gh-pages再试一次,但得到了同样的错误。

在 Yeoman 部署页面上,我在一些常见错误部分下看到

您可能会收到这样的错误更新被拒绝,因为您当前分支的尖端落后。你可以通过强制推送到遥控器来解决这个问题(不过要小心,它会破坏已经存在的东西)。

我很担心强迫它,subtree push因为我一般是 git 新手,不知道什么会被破坏。我的意思是,我目前gh-pages在我的 maxmythic_angularorigin遥控器上没有分支,所以我并不担心,但我在那里有我的master,gh-pages-oldgh-pages-v1分支。如果我跑,它们会被摧毁git subtree push --prefix dist origin gh-pages吗?

4

2 回答 2

13

Yeoman 的网站上有一个部署指南git subtree,介绍如何使用.

从导游...

当您运行 grunt build 时,它会在可以部署的 dist 目录中生成应用程序的完全优化版本。

部署 dist 目录的推荐方法是使用 git subtree。

  1. 从 .gitignore 文件中删除 dist 目录。

  2. 将 dist 目录添加到您的存储库并将其与您的项目一起提交。

    git add dist && git commit -m "Initial dist subtree commit"

  3. 一旦 dist 目录成为您项目的一部分,我们就可以使用 git subtree 在不同的分支上设置单独的存储库。注意:prefix 必须是 dist 目录的相对路径。这是假设 dist 在您的根目录中。

    git subtree push --prefix dist origin gh-pages

  4. 现在,您可以在默认(主)分支中提交整个存储库,并且无论何时要部署 dist 目录,您都可以运行:

    git subtree push --prefix dist origin gh-pages

于 2013-07-18T02:53:29.193 回答
0

我建议使用grunt-build-control。那里的使用指南正是您的情况。

我用它来部署我的用户.github.io,实际代码在 branchsource中,优化的网页构建在本地dist文件夹(在 .gitignore 中),然后master使用部署到分支grunt buildcontrol:dist

buildcontrol: {
  dist: {
    options: {
      remote: 'https://github.com/user/user.github.io',
      branch: 'master',
      commit: true,
      push: true
  }
}
于 2016-04-15T11:11:42.100 回答