Good day!

On bitbucket I delete the repository, in cmd I execute:

git reset --hard git remote rm 

I create a new repository with the same name on bitbucket.

 git init git remote add origin <repository_https_url_from_bitbucket> git add README.md git add .gitignore git commit -m “init” git add . git commit -m “test tasks” git push -u origin --all 

and again on bitbucket all the old commits. where else did I forget to delete something?

  • 2
    so you don't remove any commits from the local turnip - etki

1 answer 1

How to delete the commit history in the repository:

Locally

On the remote repository

(for example, Bitbucket, GitLab, GitHub, etc.):

Recreating the repository is basically optional. If you have already reset the local history, you can simply send it to a remote repository with the -f .

 git push -f origin 

Attention, this cannot be done if someone other than you is using the repository! ( More on why this is and what it will be for. )

This will only replace the contents of the origin/master branch. If there are other branches on the remote repository, you can delete them as follows (separately for each branch with the name, for example, branchname ):

 git push origin :branchname 

Of course, if there are a lot of branches and / or tags, it will be easier to delete and re-create the entire repository.

What happened, why did the old commits

Let us analyze all executed commands in sequence.

 git reset --hard 

Just reset local changes.

 git remote rm 

It does not work without another argument, you just did not notice the error. But even if you do this:

 git remote rm origin 

This will only remove the entry in the local repository configuration of the connected repository (remote) under the name origin .

Farther:

 git init 

If this command is executed in an existing repository, then it does nothing . If you want to delete the change history and start versioning from scratch, you had to go another way: How to reset the Git history?

 git remote add origin <repository_https_url_from_bitbucket> 

Since the repository named origin already in the local configuration, nothing will happen.

 git add README.md git add .gitignore git commit -m “init” git add . git commit -m “test tasks” 

Just add a couple of commits to the local repository. If there were no changes at some step (files that did not contain changes were added / indexed), then there was no commit.

 git push -u origin --all 

And push the result to the origin repository. Naturally we see there all the same history of commits that we have locally. You can look at the local one, for example, like this:

 git log --oneline --graph --decorate --all 

  • And if he managed to fill in the tags, oh, he is tortured to delete manually, if there are more than 10. - 0andriy
  • @ 0andriy added a little response. But I have little idea of ​​the situation when there are already many branches or tags in the repository and suddenly you need to start the story from scratch. Tags are usually something valuable is indicated like releases, why should they lose. - Nick Volynkin ♦