I load on git some project which contains some personal data. Now I changed all lines and commit it. Now I need to erase all commits except last one to prevent loosing personal data.
            Asked
            
        
        
            Active
            
        
            Viewed 4,979 times
        
    5
            
            
        - 
                    The best way is to merge all commits into one, which is answered by this question: http://stackoverflow.com/questions/7425725/how-to-merge-all-previous-commits-into-a-single-commit?rq=1 – Jon Cairns Mar 25 '13 at 14:43
- 
                    finally, I just bought account to hide this code – Aleksandr Apr 23 '13 at 19:36
2 Answers
13
            
            
        Given that your main branch is called master, and you want to remove all commits except the last one from your master:
- git checkout --orphan tmp
- git add . --all
- git commit -m "Init."
- git push origin tmp
- On your remote git repo select tmp as main branch
- git branch -D master
- git push origin :master
- git checkout -b master
- git push origin master
- On your remote git repo select master as main branch
- git branch -D tmp
- git push origin :tmp
 
    
    
        Stephan Kristyn
        
- 15,015
- 14
- 88
- 147
0
            
            
        The easiest solution is to remove the .git directory.
Open the Linux Terminal.
Move to your repository and:
cat .git/config
Note the url variable and the name of the branch:
$my_url
$my_branch
rm -rf .git
git init
git add .
git commit -m "Initial commit"
git remote add origin $my_url
git push -u --force origin $my_branch
I made this bash script which can be improved. Awaiting suggestions.
 
    
    
        Claudio Fsr
        
- 106
- 6
