Git reset

zini9188·2022년 12월 20일

Git

목록 보기
2/2

로컬 저장소의 커밋을 삭제하기

  • commit을 바로 이전 상황으로 돌리는 경우

    git reset HEAD^

  • --hard 옵션을 사용하면 돌아간 커밋 이후의 변경 이력은 모두 삭제

    git commit -m "1"
    git commit -m "2"
    git commit -m "3"

    git reset --hard [1번commit hash]
    git push

    • 2,3번 커밋 반영 내용이 사라진다.
  • --mixed 변경 이력은 모두 삭제하지만 변경 내용은 남아있다.

    git commit -m "1"
    git commit -m "2"
    git commit -m "3"

    git reset --mixed [1번commit hash]
    git add .
    git commit -m "~"
    git push

    • 이력은 날아가나 unStage 상태로 코드는 남아있다.코드를 반영하기 위해서는 add이후 stage에 반영하고 commit한다.
  • --soft 변경 이력은 모두 삭제하지만 변경 내용은 남아있다. 그러나 stage 상태이다.

    git commit -m "1"
    git commit -m "2"
    git commit -m "3"

    git reset --soft [1번commit hash]
    git commit -m "~"
    git push

    • add 명령어 필요없이 바로 commit이 가능하다.

주의점

  • 다른 사람과의 코드가 공유될 때 reset을 사용하면 모든 코드가 사라질 수 있으므로 주의하자
profile
똑같은 짓은 하지 말자

0개의 댓글