Programming - cpueblo.com

Git 최근 5개만 남기고 모두 삭제하기


글쓴이 : 유광희 날짜 : 2017-02-08 (수) 11:46 조회 : 16703
개인적으로 DB 백업을 git 으로 하고 있습니다.

1년이 넘어가기 히스토리가 50g 를 차지하고 있네요.

과감하게 최근 5개만 남기고 모두 삭제하기로 결정하여 검색하여 알려 드립니다.

1. git config 에 rebase-last-five 를 생성

# git config --global alias.rebase-last-five '!b="$(git branch --no-color | cut -c3-)" ; h="$(git rev-parse $b)" ; echo "Current branch: $b $h" ; c="$(git rev-parse $b~4)" ; echo "Recreating $b branch with initial commit $c ..." ; git checkout --orphan new-start $c ; git commit -C $c ; git rebase --onto new-start $c $b ; git branch -d new-start ; git gc'

2. git rebase-last-five 실행
# git rebase-last-five

즐거운 생활 되세요 ^^