Adding comments in a blog post in a way that it is not added to the generated HTML

When I write content for a page I have sometimes multiple ideas how to write it down. Usually I use the HTML comment syntax (<!-- some content -->)to hide stuff I don’t want to have on the webpage. This works in general great, with one small drawback. If someone looks at the source code of the webpage they will see the multiple versions of the paragraph and search engines might index it as well.

Is there a way to comment stuff out in a .md file in a way that Hugo will ignore it completely while generating the html pages?

If those comments stay in the resulting output then you have disabled “safe HTML” somewhere in your options, because typically GoHugo would strip out all HTML tags. If that is not an option for you (at least give it a thought) then my advise would be to use a shortcode that returns one single space and use the stuff between the shortcode’s opening and closing tag as your comment.

Inside of template files you can always {{/* comment out stuff */}}, but I assume we are talking about content files here.

{{< comments >}}
My comments here
{{< /comments >}}

and in layouts/partials/comments.html:

{{ $something := .Inner }}
&nbsp;

You need to at least “load” the .Inner or GoHugo will throw an error. And you need to return something or GoHugo will throw an error (I think, might have changed over time).
Not tested.

In its default configuration, Hugo removes HTML comments from the published page when you build your site with the --minify flag.

With v0.137.1 and later, use the the comment shortcode to add comments to the body of your Markdown. You can learn more about this change here.