상황은 3개의 commit을 git 서버에 push 했는데
코드가 잘못된걸 뒤늦게 확인해 roll-back 하고 싶을때 revert 하는 예시입니다.

상황: 3개의 commit을 git 서버에 push 한 상태

  • git commit -m 'test 1'
  • git commit -m 'test 2'
  • git commit -m 'test 3'
  • git push origin master

확인: revert 진행할 commit에 대한 hash 확인

  • git log
commit <COMMIT_HASH_3> (HEAD -> master, origin/master, origin/HEAD)
Author: ...
Date: ...

test 3

commit <COMMIT_HASH_2>
Author: ...
Date: ...

test 2

commit <COMMIT_HASH_1>
Author: ...
Date: ...

test 1

해결: 적용한 3개의 commit을 역순으로 하나씩 revert 하기

tip. revert 할때마다 revert commit history가 남는데, --no-commit 옵션을 사용하면 revert history를 1줄로 숨길 수 있음

  • git revert --no-commit <COMMIT_HASH_3>
  • git revert --no-commit <COMMIT_HASH_2>
  • git revert --no-commit <COMMIT_HASH_1>
  • git commit -m 'Revert 3 commits'
  • git push origin master



출처: https://jupiny.com/2019/03/19/revert-commits-in-remote-repository/

+ Recent posts