본문 바로가기

기타

[Git] Initial Commit 되돌리기

새로운 git 레포지토리에 기분좋게 Initial Commit을 잘못 푸시 해버리고.. 

"아.." 이렇게 다시 당황하지 않도록 메모

 

평소 잘못된 커밋같은 경우에는

되돌리려고 revertgit reset --hard 후, git push -f를 하려고 하지만 Initial Commit은 이전으로 reset을 할 수가 없다.

 

개인적으로 만든 레포면 레포 삭제 후 다시 만드는것도 하나의.. 방법이지만

그룹으로 쓰고, 인원들 초대까지 다 해놨는데 이걸 다시.. 또? 만들고 추가하기에는 이래저래 귀찮(민폐)

 

그래서 찾은 방법은 아래 방법

 

1. --orphan 옵션을 사용해서 새로운 고아 브랜치를 만들고 해당 브랜치로 checkout

2. Initial Commit을 잘못한 main 브랜치 삭제 

3. 현재 브랜치를 main으로 브랜치 명 변경

4. 원격 저장소로 강제 푸시

 고아 브랜치는 하나의 git repository에서 다른 브랜치나 커밋으로부터 단절된 새로운 history를 가지는 브랜치

 

 

 

+참고

 

Make the current commit the only (initial) commit in a Git repository?

I currently have a local Git repository, which I push to a Github repository. The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this. What I'd like t...

stackoverflow.com

 

반응형