Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k 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 (50.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.

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...