1

I found this question which explains Change the author and committer name and e-mail of multiple commits in Git When run any of the scripts/commands given here, are the original commits still stored in my local repo? Is there a way to get rid of them?

Community
  • 1
  • 1
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268

1 Answers1

4

Yes. The original commits will remain in your git repository. If you look at git reflog, you can see the history of recent changes. The commits will remain permanently so long as they are referenced somewhere. So, for example, if you have a branch with the original commits, they will never be deleted. However, if the commits have been orphaned (i.e. they are not accessible from any ref), then they will eventually be deleted when git gc is run. However, the default is for this to not happen for 30 days. To force this to happen immediately, you can run:

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

Use with caution, as you don't want to accidentally lose data you wanted. This will delete any unreferenced commits.

djs
  • 4,626
  • 2
  • 28
  • 38
  • For the commits to be unreachable, the gc command should be preceded by `git reflog expire --all`, otherwise they will remain reachable from the reflog. – user4815162342 Sep 15 '12 at 23:14
  • You are correct, I have updated the answer. I shot myself in the foot, of course, by mentioning the reflog and then forgetting this. – djs Sep 15 '12 at 23:24
  • How do I see what will be deleted before running these commands? – Code-Apprentice Sep 16 '12 at 00:31
  • You can run `git fsck --unreachable` to show orphaned objects. This should include everything that would be removed. – djs Sep 16 '12 at 01:32