Hexo: Git Deploy always deletes all my previous commits

Created on 29 Jan 2017  ·  26Comments  ·  Source: hexojs/hexo

I'm wondering the proper steps of using Hexo to publish a post to my Github Pages.

Here are my steps:

  1. hexo new post "my new post"
  2. hexo generate
  3. hexo deploy (this is the disaster command)
    After hexo deploy, all my previous commits will be deleted away on my Github pages, what did I do wrong? Please help.

Then I did extensive research and tried another way, I simply followed this official tutorial. What I do is:

  1. hexo new post "my new post"
  2. git add .
  3. git commit -m "commit message"
  4. git push

But my personal website doesn't show my new posts at all. What did I do wrong?

Environment Info

Node version(node -v)

v7.2.0

Most helpful comment

@fishercoder1534 Current, the deploy branch is the same as the source branch, both are master. Therefore, when you run the hexo d, it will overwrite your source code.

I'll show you what I did for my website.

  1. Put Hexo source code in the master branch;
  2. Create a gh-pages branch for website;
  3. Config the deployer branch to gh-pages;
  4. Then run the following command to deploy website and update repo.
hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch
git add . && git commit -m "." && git push # Push source to the master branch 

image

All 26 comments

For the commit history is missing, because Hexo git deployer using the force push. This is a known issue. https://github.com/hexojs/hexo-deployer-git/issues/33

The generated website files are in the public folder.

@NoahDragon Thanks for the reply.

But how can I have my posts publicly viewable on my website, I know it's in public folder, but still it's not seen on my website, did I miss any configs or I need to enable anything?

Thanks.

Could you please paste the _config.yml?

Thanks @NoahDragon , here it is below. Please let me know what else is needed or what I configured wrong in my _config.yml.
Thank you so much!

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Fisher Coder
subtitle:
description: A developer/husband/son/father.
author: Steve Sun
language: en
timezone: America/Los_Angeles

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://fishercoder.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:

# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
  enable: true
  line_number: true
  auto_detect: false
  tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repo: https://github.com/fishercoder1534/fishercoder1534.github.io.git
  branch: master
  message: 

# Disqus comments
disqus_shortname: fishercoder-com  

# Google Analytics Tracking ID
google_analytics: UA-XXXXXX

It's also publicly open here.

First of all, please split the source and site branches. Currently, they are mixed. You could create a branch name site, and change the branch in _config.yml to site.

The new post is not showing, which I assume you didn't run the hexo g command.
image

Thanks. I'll separate them.

I don't dare to run hexo g any more.
As you can see in this issue statement, whenever I do hexo g and then hexo deploy, it does a force git push which always erases all of my previous commits.

I believe this should not happen, how do you do hexo g and hexo d?
What's the best practices here?

BTW, what do you mean specifically by this?
First of all, please split the source and site branches. Currently, they are mixed. You could create a branch name site, and change the branch in _config.yml to site.

Which particular folders should I split?
And why do I need to create a branch?

I'm lost here.
I've read Hexo documentation again, but I still didn't find any instructions about this.

I've looked at your Github, but I didn't find your site repo, could you point me to any example sites please?

Thanks a lot!

@fishercoder1534 Current, the deploy branch is the same as the source branch, both are master. Therefore, when you run the hexo d, it will overwrite your source code.

I'll show you what I did for my website.

  1. Put Hexo source code in the master branch;
  2. Create a gh-pages branch for website;
  3. Config the deployer branch to gh-pages;
  4. Then run the following command to deploy website and update repo.
hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch
git add . && git commit -m "." && git push # Push source to the master branch 

image

Great! This is an awesome post! It's super helpful to newcomers like me. I'll write a blog to document this to facilitate all other Hexo-lovers.

But one more question to clear myself out:

Which folders should be categorized as Hexo source code, I did hexo init docs again and found these folders are:
_config.yml node_modules package.json scaffolds source themes
Is that right? Did I miss anything?

And the remaining folders should be put into gh-pages branch, right?

Thanks a lot again!

You're welcome.

You're right, the files and folders after hexo init are Hexo source. If you run hexo g, it will create a public folder for generated web site.

Here is a .gitignore file I used for my Hexo source:

.deploy_git/
/db.json
node_modules/
public/
yarn.lock

Thanks @NoahDragon
But I'm still having some trouble working this out. And I cannot make it sort out after many hours. Pretty frustrating.

  1. I followed the steps you said, separate out Hexo source code with other generated files into two branches, master and gh-pages, changed the deployer branch to gh-pages, and followed your steps here:
hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch
git add . && git commit -m "." && git push # Push source to the master branch 

But still, my new posts are NOT being shown on my website.

  1. I tried the above steps in both gh-pages and master branch, neither worked.
    hexo new post "post1" simply doesn't work on gh-pages branch because this branch doesn't have Hexo source code like package.json
    hexo new post "post1" works on master branch, but after hexo g and hexo d, although it's deployed to gh-pages branch, my website still doesn't show my latest posts. This is after I did git add . && git commit -m "." && git push # Push source to the master branch

  2. Also, this question is still here:
    when I do hexo d, although it's deployed to gh-pages branch, it's still forced update, erasing all of my previous commits, this is STILL happening! I cannot wrap my head around it! I tried many times tonight, still no luck.
    This seemingly very smooth process is causing me so much trouble.

Please help!
Thanks a lot!

@NoahDragon Hi! I also met this problem. I was wondering do I need to configure website.github.io corresponds to gh-pages instead of master? Thanks in advance :)

Yes, in your github repo, you have to set the default website entry to the branch gh-pages. I think this is the only reason you couldn't see the new post.

@NoahDragon Thanks. But believe it or not, Github does NOT allow me to change the publish source to gh-pages branch:
image

It's editable on your site?

@fishercoder1534 Hi there!

I cannot change to gh-pages in the options as well. But if you would please read the documents there user page site cannot be published from gh-pages. But you can still change default branch from branches (you can find it on the left column). But I do not think it's gonna help with the situation. Besides, you need to make gh-pages stop tracking master if you haven't already done.

Anyway, I am a bit tired of writing my commits every time so I will just let hexo d -g do its job. But it is nice to know how to write the commit and how git works.

Cheers!

@fishercoder1534 I think that is because it is your root website in github. You could do it in reverse way, put the website in the master branch, and create a hexo branch for the hexo source. Modify the _config.yml accordingly.

My website is in another repo, therefore I didn't have your issue. E.g. I have root github page repo: noahdragon.github.io, I have another repo en hosting my website, then the default url is noahdragon.github.io/en.

Thanks for your reply. :)

But I've tried many times and I'm still very lost so far.

I followed your steps on gh-pages branch:

hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch

And I've changed the deploy branch to gh-pages branch.
But still two problems persist:

  1. It keeps overwriting all of my previous commits, on gh-pages branch.
  2. The new post is not showing up on my site.

What else am I missing?
Any detailed instructions would be helpful.

@fishercoder1534 The first issue is a known issue, and Hexo will not fix it.
The second issue I assume the default website still point to the master branch.

Could you please show the gitpage setting?
image

Thanks @NoahDragon.
That's right, it's still pointing to master branch.
image

Could you please elaborate a little more the alternative way please? Since User pages must be built from the master branch.

Thanks.

As the master branch can't change, you could move the Hexo source code out the master branch to a new branch saying hexo, and the master branch will use as the old gh-pages to host the web pages.

Moreover, set the default branch to hexo in the repo setting.

Thanks.

I'm still trying to figure it out:

  1. Where should I run hexo new post "New Post", on master branch or gh-pages branch?
    Looks like I have to run it where hexo source code remains, otherwise it doesn't run and returns me this:
Usage: hexo <command>

Commands:
  help     Get help on a command.
  init     Create a new Hexo folder.
  version  Display version information.

Global Options:
  --config  Specify config file instead of using _config.yml
  --cwd     Specify the CWD
  --debug   Display all verbose messages in the terminal
  --draft   Display draft posts
  --safe    Disable all plugins and scripts
  --silent  Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

But when I run it on master branch where Hexo source code resides, after configuring deployment options to gh-pages, and following

hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch

My gh-pages got overwritten again, erased all of my previous commits in this gh-pages branch.
Here's what my terminal shows after hexo d on master branch:

To https://github.com/fishercoder1534/engineering.git
 + d2d8118...33dcf75 HEAD -> gh-pages (forced update)
Branch master set up to track remote branch gh-pages from https://github.com/fishercoder1534/engineering.git.
INFO  Deploy done: git

I'm just following the official doc here which never talks about setting up a different branch to store hexo source code, I think we need to have a page as best practices for Hexo.

Could you please list out the steps of how you configure Hexo with Github Pages and the blogging process? I'm sure this will benefit an entire group of Hexo lovers.

  1. Details including on which branch to run hexo init <folder>, on which branch/folder to run
hexo new post "New Post"
hexo g # Generate the new post
hexo d # Deploy to gh-pages branch
  1. Details on which branch/folder to run
git add . && git commit -m "." && git push
  1. What settings do we need to change on Github repo settings.

  2. If you could list out your blogging steps/workflow, that would be super beneficial.

I really appreciate your help.
Apologies for dummies like me who spent 4 weekends in a row on this but still haven't figured it out yet. :)

All questions are good. You are right, we need a more clear help document.

To run Hexo command, you have to do it in the hexo source folder, in your scenario it is the master branch.

The git deployer erasing all deploy branch history is by design. People have discussed it in this issue https://github.com/hexojs/hexo-deployer-git/issues/33 .

I just wonder if the new post has properly displayed on your site?

Thanks.

But no luck on making new posts show up on my site.

I actually gave up on using Hexo with Github Pages, fell back to my old wordpress powered site already.

Feel free to close this issue.

Hexo is required background on HTML/JS/CSS, Node, YAML, JSON, Git, EJS, and etc. to play it. One of my sites also using Wordpress, and found it much easier for non-computer background people to use.

Has the same issue, followed all the stuff that listed here no luck. any info about this bug?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lushijie picture lushijie  ·  3Comments

hgDendi picture hgDendi  ·  3Comments

jakeg picture jakeg  ·  3Comments

yunTerry picture yunTerry  ·  3Comments

Helihua1992 picture Helihua1992  ·  3Comments