How to migrate git history when using `hugo import`?

This is really a git question, not a hugo question, but I’m probably not the only hugo user who has been through this…

I have a pre-existing jekyll blog which I’ve kept for many years in a git repository, like this:

├── jekyll
│   └── _posts
│       ├── 2017-09-29-some-post.md
│       ├── 2017-10-18-some-other-post.md

I can migrate all my content over to hugo by way of hugo import jekyll jekyll_root_path target_path, and that leaves me with new hugo files like this:

├── hugo
│   ├── content
│   │   ├── post
│   │   │   ├── 2017-09-29-some-post.md
│   │   │   ├── 2017-10-18-some-other-post.md

Does anyone know how I can keep the git history of the old posts? Preferably I’d like to be able to use the git blame interface on GitHub and be able to trace all the history of the posts back to their jekyll origins, rather than treating the hugo posts as entirely new files.

The old jekyll content and the new hugo content both live in the same repository, it’s not two different repositories or anything. The old jekyll content will be deleted and I’d be happy if the new hugo content appeared in git as if it was the result of git mv jekyll/_posts/2017-09-29-some-post.md hugo/content/post/2017-09-29-some-post.md or similar.

Thanks.

unfortunately the command does not print out complete source and target paths but if you know which source file will result in which target file fe if all your filenames in jekyll/posts are unique

taking your structure from above I could think of something like that

  • import to a temp folder like NEW

    ├── NEW
    │   ├── content
    │   │   ├── post
    │   │   │   ├── 2017-09-29-some-post.md
    │   │   │   ├── 2017-10-18-some-other-post.md
    
  • create a folder hugo

  • move each source file from old to new structure

    for each file in jekyll
      find the matching `jekyll/source_path/file.md` in the `new` as `NEW/target_path/file.md`
      git mv source_path/file.md hugo/target_path/file.md # this will automatically stage it
    end
    git commit -m "moved files to hugo structure"
    
  • overwrite the moved files with the migrated one

    foreach file in NEW
     cp NEW/file hugo/file
    end
    git add hugo
    git commit -m "migrated content to hugo"
    
  • make sure your searches are correct and you got all files

  • remove NEW and jekyll folders if all went fine and you are confident with the result

you could also do it per file file basis using

for each file in jekyll
  find the matching `jekyll/source_path/file.md` in the `new` as `NEW/target_path/file.md`
  git mv source_path/file.md hugo/target_path/file.md # this will automatically stage it
  cp NEW/target_path/file.md hugo/target_path/file.md
  git commit -m "migrated source_path/file.md to hugo structure"
end

Thanks @irkode , your approach pointed me in the right direction and I got this to work.

All of my new Hugo post filenames exactly matched all of the old Jekyll post filenames, so I was able to do it like this:

hugo import jekyll jekyll_root_path hugo_root_path
for HUGOFILEPATH in $(find hugo_root_path/content/post -type f)
do
  BASENAME=$(basename $HUGOFILEPATH)
  cp $HUGOFILEPATH jekyll_root_path/_posts/${BASENAME}
  git mv -f jekyll_root_path/_posts/${BASENAME} $HUGOFILEPATH
done

And then my jekyll image assets/ directory exactly matched the same filenames and same content as my hugo static/assets/ directory, so I just did git mv on that entire directory.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.