How to fix my renaming of a post filename

Hello, I am new to Hugo, and somewhat new to Git. I recently installed Hugo v0.108.0 and git 2.38.2 on my Mac. I successfully created my first blogging post (using the hugo new command), then deployed it to Github, and Github Pages successfully built the website. My problem is this: I renamed the post filename on my mac (using “mv” command), and now after pushing changes to Github, my website show two identical posts instead of just one. Is there an easy way to fix this (or reset it)?

Is GitHub building your site (i.e., CI/CD deployment), or are you just checking in your public directory?

I believe Github is building my site. I set up a Github Action Workflow to build the website every time I git push to my repository. Thanks for replying

It sounds like (a) you are pushing your public directory, and (b) GitHub pages is deploying your site instead of building and deploying your site.

Can you point us to the public repository for your site? That would be really helpful.

I assume you mean this, which is address of the repo?

You have two identical posts with the same title in the content directory.

content/
└── posts/
    ├── first-post-121222.md
    └── ttcp-121222.md

Delete one of them, commit your changes, and push.

With your last commit, you may have added the new file, but not deleted the old one. Look into the git add command. These do different things:

  • git add *
  • git add .
  • git add -u
  • git add -A

The first-post-121222.md file doesn’t exist anymore on my local machine - I just renamed it (to ttcp-121222.md). Then committed and pushed, which resulted in this situation. Here’s a file list:

paulb@MacBook-Air-2 posts % pwd
/Users/paulb/hugo-blog2/content/posts
paulb@MacBook-Air-2 posts % ls -l
total 16
drwxr-xr-x 3 paulb staff 96 Dec 15 18:00 ./
drwxr-xr-x 3 paulb staff 96 Dec 12 18:30 …/
-rw-r–r-- 1 paulb staff 5436 Dec 15 14:02 ttcp-121222.md

Type git status and post the result.

Thank for the help, here is the git status:

paulb@MacBook-Air-2 posts % git status
On branch main
Your branch is up to date with ‘origin/main’.

Changes not staged for commit:
(use “git add/rm …” to update what will be committed)
(use “git restore …” to discard changes in working directory)
deleted: first-post-121222.md

Untracked files:
(use “git add …” to include in what will be committed)
…/…/.hugo_build.lock
…/…/public/
…/…/resources/

no changes added to commit (use “git add” and/or “git commit -a”)
paulb@MacBook-Air-2 posts %

See this bit?

Changes not staged for commit:
(use “git add/rm …” to update what will be committed)
(use “git restore …” to discard changes in working directory)
deleted: first-post-121222.md

That means you didn’t add the “deletion” to your commit.

Do this:

git add -A
git status

and post the result

paulb@MacBook-Air-2 posts % git add -A
paulb@MacBook-Air-2 posts % git status
On branch main
Your branch is up to date with ‘origin/main’.

Changes to be committed:
(use “git restore --staged …” to unstage)
new file: …/…/.hugo_build.lock
deleted: first-post-121222.md
new file: …/…/public/404.html
new file: …/…/public/avatar.jpg
new file: …/…/public/categories/index.html
new file: …/…/public/categories/index.xml
new file: …/…/public/css/main.min.9e9c6027c30f5aa9423b581bd9cddd1ddc66088adb9c2604f89eb5828efea5a1.css
new file: …/…/public/index.html
new file: …/…/public/index.xml
new file: …/…/public/page/1/index.html
new file: …/…/public/sitemap.xml
new file: …/…/public/tags/index.html
new file: …/…/public/tags/index.xml
new file: …/…/resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.content
new file: …/…/resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.json

paulb@MacBook-Air-2 posts %

Oh no.

First, let’s unstage everything (there’s a dot at the end of the command):

git restore --staged .

Next, let’s create a .gitignore file in the root of your project:

touch .gitignore

Now edit that file so it looks like this:

.hugo_build.lock
/node_modules
/public
/resources

The do this again:

git add -A
git status

and post the result

Here’s output from all the commands you suggested:

paulb@MacBook-Air-2 posts % git restore --staged .
paulb@MacBook-Air-2 posts % git status
On branch main
Your branch is up to date with ‘origin/main’.

Changes to be committed:
(use “git restore --staged …” to unstage)
new file: …/…/.hugo_build.lock
new file: …/…/public/404.html
new file: …/…/public/avatar.jpg
new file: …/…/public/categories/index.html
new file: …/…/public/categories/index.xml
new file: …/…/public/css/main.min.9e9c6027c30f5aa9423b581bd9cddd1ddc66088adb9c2604f89eb5828efea5a1.css
new file: …/…/public/index.html
new file: …/…/public/index.xml
new file: …/…/public/page/1/index.html
new file: …/…/public/sitemap.xml
new file: …/…/public/tags/index.html
new file: …/…/public/tags/index.xml
new file: …/…/resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.content
new file: …/…/resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.json

Changes not staged for commit:
(use “git add/rm …” to update what will be committed)
(use “git restore …” to discard changes in working directory)
deleted: first-post-121222.md

paulb@MacBook-Air-2 posts % cd …
paulb@MacBook-Air-2 content % cd …
paulb@MacBook-Air-2 hugo-blog2 % touch .gitignore
paulb@MacBook-Air-2 hugo-blog2 % ls
./ .github/ .hugo_build.lock config.toml layouts/ static/
…/ .gitignore archetypes/ content/ public/ themes/
.git/ .gitmodules assets/ data/ resources/
paulb@MacBook-Air-2 hugo-blog2 % vi .gitignore
paulb@MacBook-Air-2 hugo-blog2 % cat !$
cat .gitignore
.hugo_build.lock
/node_modules
/public
/resources
paulb@MacBook-Air-2 hugo-blog2 % git add -A
paulb@MacBook-Air-2 hugo-blog2 % git status
On branch main
Your branch is up to date with ‘origin/main’.

Changes to be committed:
(use “git restore --staged …” to unstage)
new file: .gitignore
new file: .hugo_build.lock
deleted: content/posts/first-post-121222.md
new file: public/404.html
new file: public/avatar.jpg
new file: public/categories/index.html
new file: public/categories/index.xml
new file: public/css/main.min.9e9c6027c30f5aa9423b581bd9cddd1ddc66088adb9c2604f89eb5828efea5a1.css
new file: public/index.html
new file: public/index.xml
new file: public/page/1/index.html
new file: public/sitemap.xml
new file: public/tags/index.html
new file: public/tags/index.xml
new file: resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.content
new file: resources/_gen/assets/scss/css/main.scss_e86386c8bae1cd02295de71a1be078d6.json

paulb@MacBook-Air-2 hugo-blog2 %

Did you issue these commands from the root of your project?

The last vi/git add -A/git status commands were all done from the root dir. All the previous commands you had me do were done in the contents/posts subdirectory:

paulb@MacBook-Air-2 hugo-blog2 % pwd
/Users/paulb/hugo-blog2
paulb@MacBook-Air-2 hugo-blog2 % ls
./ .github/ .hugo_build.lock config.toml layouts/ static/
…/ .gitignore archetypes/ content/ public/ themes/
.git/ .gitmodules assets/ data/ resources/
paulb@MacBook-Air-2 hugo-blog2 %

All of the commands that I gave you must be run from the root of your project.

When you’re working on Hugo site, there’s rarely a reason to leave the root directory.

Do it again. All of it.

And delete the .gitignore file you created in contents/posts.

The .gitignore I did create in the root directory, not contents/posts:

paulb@MacBook-Air-2 hugo-blog2 % ls -a content/posts
./ …/ ttcp-121222.md
paulb@MacBook-Air-2 hugo-blog2 % pwd
/Users/paulb/hugo-blog2
paulb@MacBook-Air-2 hugo-blog2 % ls -a .gitignore
.gitignore
paulb@MacBook-Air-2 hugo-blog2 %

Have you run the commands again, from the root directory this time?

not yet, I’ll do it now