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
Github has a good article about removing sensitive data (so the commits you want too):
Remove Sensitive Data from Git
Was trying to follow @vergenzt answer but git started to apply patches from the 1st commit which was 3000+ commits before the one I needed to start from.
My purpose was to make smaller repo for the new project that is based on current one. Unfortunately I needed some history to be preserved from current project (several months). This is how I finally managed to do it:
Command line tool was not quite convenient to do this because you will need to resolve conflicts. Fortunately there is a Rebase feature in TortoiseGit where you need to provide 2 barnches: master (left) and temp (right). Then skip all commits before the one where your temp branch on including commit (select commits and use 'skip' in right click menu). After rebase started you will get some conflicts which you can resolve right in the rebase GUI. I always picked "use master branch version" in right click menu. This took much less time then bothering with CLI. After everything was done I've additionally copied all project files from latest version of original repository upon files in new repository (overwrite all) to make sure nothing lost. I've got only several files that were in .gitignore and somehow were not ignored. Other files were same.
I hope this helps someone.
Assuming master
is at commit F
:
# create a new branch with D's content
$ git checkout --orphan temp <d-sha1>
$ git commit
# rebase everything else onto the temp branch
$ git rebase --onto temp <d-sha1> 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
I know that's an old question, but I landed here today searching about this topic...
For the large amount of commits problem, you can try using "-X theirs" or "-X ours" in the rebase command, i.e.
git rebase -X theirs -i HEAD~20
the difference between the two it's explained here
I hope that can be useful to someone