Program Club

이전 git 커밋 제거

proclub 2020. 10. 26. 21:31
반응형

이전 git 커밋 제거


나는 git을 처음 접했고 이와 같은 것이 가능한지 궁금해하고 있습니까?

>git log --pretty=oneline --abbrev-commit
2f05aba Added new feature
3371cec Fixed screw up    <-- I want to remove this
daed25c Screw up          <-- and remove this.
e2b2a84 First.                So it's like they never happend.

이것이 가능한가?


이것은 git rebase. 다음을 시도하십시오

git rebase -i HEAD~4

그런 다음 편집기의 대화 형 지침을 따릅니다. 첫 번째 단계에서는 커밋을 "스쿼시"합니다. 다음과 같이 보일 것입니다.

pick 2f05aba ... will be preserved
squash 3371cec ... will be squashed with daed25c
squash daed25c ... will be squashed with e2b2a84
pick e2b2a84 .. will contain this and 3371cec and daed25c

두 번째 단계에서는 커밋 메시지를 편집 할 수 있습니다.


진정으로 삭제하려면 (기록에서 삭제하고 더 이상 표시되지 않음)

rebase 실행 :

git rebase -i HEAD~4

그런 다음 삭제하려는 커밋에 해당하는 줄을 다음과 같이 삭제 (또는 주석 처리)합니다.

pick 2f05aba ... #will be preserved
#pick 3371cec ... #will be deleted
#pick daed25c ... #will be deleted
pick e2b2a84 ... #will be preserved

Squash는 단일 해시로 병합 된 커밋 목록을 생성하려는 경우 유용하지만 세 개의 개별 커밋을 사용하고 단일 커밋처럼 보이는 최종 출력이있는 경우에는 권장합니다. fixup

git rebase -i HEAD~4

pick 2f05aba ... will be preserved
fixup 3371cec ... will be merged with daed25c
fixup daed25c ... will be merged with e2b2a84
pick e2b2a84 .. will include 3371cec and daed25c, but only the commit message of e2b2a84

대화 형 rebase UI의 명령 목록에서 자세한 정보를 찾을 수 있습니다.

참고 URL : https://stackoverflow.com/questions/9725156/remove-old-git-commits

반응형