Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete all commit history in github? [duplicate]

Tags:

git

github

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 can do this?

git filter-branch ? git rebase ? ...  

My code is hosted on github.com.

like image 675
Chinaxing Avatar asked Dec 05 '12 05:12

Chinaxing


People also ask

Can you delete GitHub commit history?

Typically, you should never delete your commit history. However, if you're working on your own project or a repository that isn't used by many people, you might want to delete your commit history without touching the code.

How do I delete multiple commits in GitHub?

git rebase -i HEAD~<number of commits to go back> , so git rebase -i HEAD~5 if you want to see the last five commits. Then in the text editor change the word pick to drop next to every commit you would like to remove. Save and quit the editor. Voila!

Does git clone copy commit history?

Each clone usually includes everything in a repository. That means when you clone, you get not only the files, but every revision of every file ever committed, plus the history of each commit.

How delete all commit messages?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.


2 Answers

Deleting the .git folder may cause problems in your git repository. If you want to delete all your commit history but keep the code in its current state, it is very safe to do it as in the following:

  1. Checkout

    git checkout --orphan latest_branch

  2. Add all the files

    git add -A

  3. Commit the changes

    git commit -am "commit message"

  4. Delete the branch

    git branch -D main

  5. Rename the current branch to main

    git branch -m main

  6. Finally, force update your repository

    git push -f origin main

PS: this will not keep your old commit history around

like image 56
Desta Haileselassie Hagos Avatar answered Oct 14 '22 05:10

Desta Haileselassie Hagos


If you are sure you want to remove all commit history, simply delete the .git directory in your project root (note that it's hidden). Then initialize a new repository in the same folder and link it to the GitHub repository:

git init git remote add origin [email protected]:user/repo 

now commit your current version of code

git add * git commit -am 'message' 

and finally force the update to GitHub:

git push -f origin master 

However, I suggest backing up the history (the .git folder in the repository) before taking these steps!

like image 24
Amir Ali Akbari Avatar answered Oct 14 '22 06:10

Amir Ali Akbari