You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法推送README.Rmd至GitHub及推送后Rmarkdown格式未正常渲染问题咨询

Why Your GitHub README Isn't Rendering Properly

Let’s break down exactly what happened and how to fix it:

The Root Cause

When you run usethis::use_readme_rmd(), it sets up two critical pieces:

  1. A README.Rmd file (your editable source document)
  2. A pre-commit Git hook that automatically renders README.Rmd to README.md before every commit.

GitHub only uses the README.md file to display a formatted preview—README.Rmd is treated as raw code because it’s a source file, not the final markdown output. By removing the pre-commit hook, you skipped the step that generates README.md, so only the unrendered Rmd file was pushed to GitHub. That’s why you see the raw code instead of a nice page.

Fixing the Immediate Issue

To get your README looking right on GitHub right now:

  1. Generate the markdown file locally:
    Run this command in your R console to convert your README.Rmd to README.md:

    rmarkdown::render("README.Rmd")
    

    If you’re using RStudio, you can also just click the "Knit" button at the top of the README.Rmd editor pane.

  2. Commit and push both files:
    In Git, stage both README.Rmd (your editable source) and README.md (the rendered output), then commit and push. GitHub will now use README.md to display the formatted page.

Preventing This From Happening Again

It’s smart to restore the pre-commit hook so you don’t have to manually render the README every time you make changes. Here’s how:

  • Re-add the usethis hook:
    Run usethis::use_readme_rmd() again. When prompted if you want to overwrite your existing README.Rmd, select "No"—this will re-create the pre-commit hook without touching your modified content.

  • Test the hook:
    Make a tiny change to README.Rmd (like adding a space), then try to commit. The hook will automatically run rmarkdown::render() for you, updating README.md before the commit goes through. This ensures your source and rendered files stay in sync every time you push.

A Quick Note on the Pre-Commit Hook

The original block you encountered was a safeguard: the hook noticed README.Rmd had changed but README.md hadn’t, so it stopped the commit to prevent you from pushing incomplete or outdated files. Removing it skips that check, but keeping it enabled is the best way to maintain consistency between your work and what’s displayed on GitHub.

内容的提问来源于stack exchange,提问作者JaFranke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 17:24:12