0 votes
1 view
in Devops and Agile by (29.9k points)

I want to delete all commit history but keep the code in its current state because, in my commit history, there are too many unused commits.

How can I do it?

Is there any git command that can do this?

git filter-branch ?

git rebase ?

... 

My code is hosted on github.com.

1 Answer

0 votes
by (51.2k points)

Here I am solving this question with a brute-force approach.

Note: This approach will not work if your repository has submodules. For repository having submodules, you should use interactive rebase.

Let’s see the brute-force approach

Remove all history(make sure you have the backup) using:

cat .git/config  # note <github-url>

rm -rf .git

Reconstruct the git repo with the current content:

git init

git add .

git commit -m "Initial commit"

Push the commit to github

git remote add origin <github-url>

git push -u --force origin master

Thus, you can make current commit to the only commit in a git repository.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...