DevOps/Git

github add, commit 취소

신웅철 2021. 11. 19. 12:38

git add를 했는데 잘못 넣었을 경우 아차싶었다. 찾아보니 다음의 명령어를 통해 add부터 commit까지 취소할 수 있었다.

 

목차

1. git add 취소

2. git commit 취소

 

git add 취소

 

git reset HEAD [file name]

 

[file name]이 없으면 add 했었던 파일 전체를 취소할 수 있다.

 

git commit 취소

 

git reset --soft HEAD^

 

commit을 취소하고 해당 파일은 staged로 git add가 되어있는 상태에서 commit을 기다린다.

 

git reset --mixed HEAD^
git reset HEAD^ # 위와 동일
git reset HEAD~3 # 최근 3개 커밋 취소

 

commit을 취소하고 해당 파일은 unstaged로 git add를 기다린다.

 

git reset --hard HEAD^

 

commit을 취소하고 해당 파일은 로컬에서도 삭제된다.