본문 바로가기
CI&CD/Git

[Git] window에서 이미 푸시된 커밋을 삭제하는 방법

by TSpoons 2024. 11. 8.

os: window 11
 
 
 
(How to delete a pushed commit on Windows OS )
git push를 했는데 저런.. 파일을 잘못 올려버렸다. 폴더 속 폴더를 올린 것이다.

이미 push된 commit 기록은 웹사이트에서 제거할 수 없다.
따라서 git을 설치하여 수정하도록 한다.
 
Git - Downloads
https://git-scm.com/downloads

 

Git - Downloads

Downloads macOS Windows Linux/Unix Older releases are available and the Git source repository is on GitHub. Latest source Release 2.47.0 Release Notes (2024-10-06) Download Source Code GUI Clients Git comes with built-in GUI tools (git-gui, gitk), but ther

git-scm.com

 
조금 더 편의를 위해 github desktop도 설치하자.
https://desktop.github.com/download/

 

Download GitHub Desktop

Simple collaboration from your desktop

desktop.github.com

 
 

1. github desktop 설치 후 repository를 선택한다.

2. git을 설치했다면 Repository -> Open in Command Prompt를 클릭

3. git log로 돌아갈 commit hash를 알아낸다.

4. 'q' 로 나가고, 다음 명령어 실행

git reset --hard d255af26d114460c79c544dfe33b72df4e097489

5 git terminal에서 push!

git push origin main

issue

6. 4번 작업인 reset을 강제로 시키고, 강제로 push하면 바뀐다.

하지만, 팀원들과 충분히 상의 후 진행하자.(팀원이 이를 모르고 작업 시 기존 작업들과 충돌이 일어날 수 있다.)

 

**그리고 복사본을 필수로 만들고 하자!**

git push -f origin main

의도한 바 완료!