1

I started to work on a project with an old and very big repo, around 1.1GB

I have made a full clone from the original repo, into another repo and called it original-repo

The project will continue only on a specific part and all other parts are deprecated, so all the commits and branches from initial commit (7e48a70) to a specific commit (222b1f3) are useless. And to make repo clean I need to delete all those commits and all branches except for master, and rewrite the history of the working repo.

I've searched and read lot of topics, used many scripts and commands, installed some Git GUI applications, but couldn't manage to delete the commits and branches to cleanup and reduce size of repo. Repo size is still 1.1GB.

Any help would be really appreciated.

Hadi Sharghi
  • 903
  • 16
  • 33
  • I have just suggested that in [another question](https://stackoverflow.com/questions/51123593/github-merging-previous-checkins#comment89237626_51123593), you could have done a [shallow clone](https://git-scm.com/docs/git-clone#git-clone---depthltdepthgt) and continue to work on that. – Tobias K. Jul 01 '18 at 19:40
  • Are you wanting to actually delete the *content* of those commits, or just have them all squashed into one monster commit? – Ryan Lundy Jul 01 '18 at 19:43
  • @RyanLundy I want to actually delete the commits. Like they never existed. I want to reduce the size of the repo. – Hadi Sharghi Jul 02 '18 at 03:55
  • @TobiasK I've tried shallow clone, but it seems when you shallow clone a repo (`original-repo`), you can't push it to another repo. – Hadi Sharghi Jul 02 '18 at 05:03
  • Yes, sorry, it actually seems you cannot push that. Makes sense, as there is an orphaned commit in history, sorry :( If there are no commits newer than 222b1f3 you want to keep you could `rm -rf .git`, and re-init, `git add .` and commit that. – Tobias K. Jul 02 '18 at 06:18

1 Answers1

0

If you wants to keep the commit log then try

git revert "HEAD^"

Otherwise you may try soft / hard reset

git reset --soft "HEAD^"

git reset --hard "HEAD^"

Please read the Difference between soft, mixed and hard reset in case of any confusion.

You can also delete your remote branch using

git push origin --delete <branch_name>

Edit

You can revert the changes between two commits using

git revert commit_id1..commit_id2
Shravan40
  • 8,922
  • 6
  • 28
  • 48
  • I want to delete commits from the initial commit to a specific commit, like they never existed, to reduce the repo size. – Hadi Sharghi Jul 02 '18 at 03:58