简体   繁体   中英

Git - how to delete old commits without affecting recent commit's sha-1?

I have huge git repository(binary files) and I want to delete old commits to shrink it's size.

Assume my commit history;

$ git log
g0g0g0 - patch 06
f0f0f0 - patch 05
e0e0e0 - patch 04
d0d0d0 - patch 03
c0c0c0 - patch 02
b0b0b0 - patch 01
aaaaaa - initial empty

And each commits has tag;

$ git tag
tag01 -> b0b0b0
tag02 -> c0c0c0
tag03 -> d0d0d0
tag04 -> e0e0e0
tag05 -> f0f0f0
tag06 -> g0g0g0

Here is what I want;

$ git log
g0g0g0 - patch 06 <- tag06
f0f0f0 - patch 05 <- tag05
e0e0e0 - patch 04 <- tag04
aaaaaa - initial empty

$ git tag
tag01 -> deleted b0b0b0
tag02 -> deleted c0c0c0
tag03 -> deleted d0d0d0
tag04 -> e0e0e0
tag05 -> f0f0f0
tag06 -> g0g0g0

Is it possible to delete old three commits(b0b0b0, c0c0c0, d0d0d0) without changing other commit's sha-1 values(g0g0g0, f0f0f0, e0e0e0)?

No, it's not possible. A commit's parents are used to compute its hash. If any part of the history changes, the commit hash will be different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM