Remove / cut off Git's revision / commit history

后端 未结 4 402
难免孤独
难免孤独 2021-02-04 04:36

I have a project that contains traces to another project of myself that I\'ve used as a kind of a template project. Now I want to remove these traces entirely from the repositor

4条回答
  •  北海茫月
    2021-02-04 05:09

    Assuming master is at commit F:

     # create a new branch with D's content
    $ git checkout --orphan temp 
    $ git commit
    
     # rebase everything else onto the temp branch
    $ git rebase --onto temp  master
    
     # clean up
    $ git checkout master
    $ git branch -d temp
    

    If you want to completely remove the old loose objects (A, B, & C), first make sure you have exactly what you want. This cannot be undone. Once you have confirmed it's what you want, run:

    $ git reflog expire --expire=now --all
    $ git gc --prune=now
    

提交回复
热议问题