Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete complete Git history without deleting the repository?

Tags:

git

github

My question might seem a bit strange since what I want can usually be accomplished by simply deleting the repository and creating a new one. Here's the reason why I still need to keep the repository: The history of my repository is actually the most valuable part of the repository. I generate an entire repository with all the data. The repository is hosted on github and I want to update the repository there to look exactly like the local repository (identical history).

The only way I have found to do this so far has been to delete and recreate the repository on github before pushing to it. Otherwise all of the old commits would still be there, effectively altering the historical information of the repository. Of course it is fairly easy to recrate a repository on github but along with the repository all watchers, wiki info etc. are lost and I'd like to prevent that.

I've posted here instead of github since I think that this question is rather related to Git than to the hosting service.

Any thoughts?

like image 474
Max Leske Avatar asked Mar 16 '11 10:03

Max Leske


People also ask

How do I remove files from my entire git history?

To entirely remove unwanted files from a repository's history you can use either the git filter-repo tool or the BFG Repo-Cleaner open source tool. The git filter-repo tool and the BFG Repo-Cleaner rewrite your repository's history, which changes the SHAs for existing commits that you alter and any dependent commits.

How do I delete a git repository without deleting?

3. Using the git rm –cached Command. We've mentioned that git rm FILE will remove files from the index and local working tree by default. However, the git rm command provides the –cached option to allow us only to remove files from the repository's index and keep the local file untouched.

How do I delete my git history in GitHub?

Run git --git-dir . gc --aggressive --prune=now locally. Completely delete the git repo from your Gitlab server.


2 Answers

A forced push such as git push origin +master should help. All remote changes will be lost.

like image 87
Alan Haggai Alavi Avatar answered Oct 14 '22 19:10

Alan Haggai Alavi


Step 1: Delete all remote branches:

git fetch
git branch -r

For each line of output (they should look like origin/master, origin/branch1, ...) add it to a git push line like this:

git push origin :master :branch1 ...

Step 2: Push your local branches

git push origin master branch1 ...
like image 20
Jonathan Avatar answered Oct 14 '22 20:10

Jonathan