我正在开发一个基本的Angular 5项目,我在github帐户的master分支中不断更新。我最近使用以下教程向github页面添加了我的项目的实时版本:here其中运行了以下命令:
ng build
git add dist
git commit -m "checking in dist folder"
git subtree push --prefix=dist origin gh-pages
以上几行只将/ dist文件夹的内容推送到远程repo origin / gh-pages,这是我的实时站点(前端)加载的地方。
因此,在我的本地仓库中进行更改并提交到我的主分支后,我也尝试同步origin / gh-pages分支(使用指南)。但我收到以下错误,我感觉我正在做(或做过)错误的事情。我对Git很陌生,我不明白这个问题。
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git branch
* master
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git checkout gh-pages
Branch 'gh-pages' set up to track remote branch 'gh-pages' from 'origin'.
Switched to a new branch 'gh-pages'
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git rebase master
First, rewinding head to replay your work on top of it...
Applying: checking in dist folder
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git status
On branch gh-pages
Your branch and 'origin/gh-pages' have diverged,
and have 17 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git push
Username for 'https://github.com': ************
Password for 'https://***********@github.com':
To https://github.com/<github username>/address-book-angular.git
! [rejected] gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/<github username>/address-book-angular.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git pull
fatal: refusing to merge unrelated histories
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git rebase master
Current branch gh-pages is up to date.
lycan@lycan-dmini110 /media/lycan/Store4/WebDevelopment/Angular/SampleProjects/address-book-angular $ git push origin gh-pages
Username for 'https://github.com': <github username>
Password for 'https://<github username>@github.com':
To https://github.com/<github username>/address-book-angular.git
! [rejected] gh-pages -> gh-pages (non-fast-forward)
error: failed to push some refs to 'https://github.com/<github username>/address-book-angular.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
答案 0 :(得分:0)
我通过删除我的远程repo origin / gh-pages(origin / master未受影响)解决了这个问题。然后运行我之前使用的以下命令(我在教程中看到):
ng build
git add dist
git commit -m "checking in dist folder"
git subtree push --prefix=dist origin gh-pages
这允许将本地主分支的最新更改推送到origin / gh-pages远程分支,并且我的站点在github页面上再次生效。