How can I delete git notes from my commit history?

Furkan Elibol
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 14, 2023

Hello,

When I looked at my commit graph, I saw some commits that are done by semantic-release-bot.

Screenshot 2023-03-14 at 12.36.27.png

I want to delete all these "git notes add" commits, but I couldn't find any way to access and remove them

  • I checked my local git log, but these commits are not shown there
  • I checked my local refs, but there is no ref named refs/notes

How can I do it?

1 answer

0 votes
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 15, 2023

Hi @Furkan Elibol and welcome to the community!

Please run the following commands in your clone of the repo:

git fetch --all
git branch --all

Does the output of git branch --all show this branch in your remote branches?

If so, and if the branch does not exist locally, you can checkout the branch locally with the command

git checkout -b branch-name origin/branch-name

where branch-name replace with the name of your branch and origin replace with the name of the branch's remote, if it is different.


Before you proceed with removing any commits, I would strongly recommend taking a backup of the repo as the process includes destructive operations. If your Bitbucket Cloud repo has all the branches and changes you have locally, you can take a backup by cloning with the mirror flag:

git clone --mirror repo_url

 

If the commits you want to remove are the last ones on that branch, after you checkout out this specific branch you can use

git reset --soft HEAD~1

where 1 replace with the number of commits you want to remove. E.g. git reset --soft HEAD~3 will remove the last 3 commits on the branch that is checked out.

If you have made other commits that you want to keep, and the commits you want to delete are not the last ones on that branch, you can use an interactive rebase to remove these commits. You can see more details in the following post in StackOverflow:

https://stackoverflow.com/a/42522493

In both cases, you will need to force-push your changes to the remote repo (push with the -f flag). Please keep in mind that pushing with the -f option will overwrite the commits on the remote (which is why it's important to have a backup in case anything goes wrong).

If you have any questions, please feel free to reach out.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events