[Git] reset 으로 되돌아가기

CODEDRAGON Development/Git, PM

반응형

 

reset 으로 되돌아가기

특정 버전으로 돌아 간 후 해당 버전 이후의 변경 내용은 취소하게 됩니다.

 

 

index.html 파일 수정하기

태그 추가

 

<strong>I Will Be Back</strong>


 

 

변경 내용 확인하기

변경 내용을 확인하는데 변경을 잘 못하였습니다. 이 내용을 취소하고 이전내용으로 되돌리도록 하겠습니다.

 

git diff


 

 

변경된 사항 모두 취소하기

"git reset --hard" 명령을 수행하면 마지막 버전 이후에 변경된 사항이 모두 삭제됩니다.

 

git reset --hard


 

 

변경된 사항이 삭제되었는지 확인하기

변경사항이 표시가 되지 않는 것을 확인할 수 있습니다.

 

git diff


 

수정한 파일의 내용 확인한 결과 이전 상태로 되돌아간것을 확인할 수 있습니다.

(추가했었던 <strong>태그가 보이지 않습니다.)

cat index.html


 

 

index.html 파일 수정하기

태그 추가

 

<b>Missing You</b>


 

 

변경상태 확인하기

 

git status


 

 

버전 대상 추가와 커밋 함께하기

변경된 파일을 자동으로 add 시킨 후 commit하게 됩니다.

 

git commit -am 'add <b> tag'


 

 

버전 변경 내용 확인하기

 

git log


 

"add <b> tag" 버전을 취소하고 "modify tag and text" 상태로 되돌리려면 취소하고 싶은 버전의 이전 버전 ID를 알고 있어야 합니다.

commit 89bcb4816b7e950eca96e0f82f3b6997750200b9

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:03:39 2017 +0900

 

    add <b> tag

 

commit 998824f58591be048bb95e05bc17de12be7bb56b

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 18:22:17 2017 +0900

 

    modify tag and text

 

commit 7f927e16cdc2a907f63ec697fbeb722301bbea50

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 15:54:17 2017 +0900

 

    add style.css

 

 

이전 상태로 되돌리기

 

git reset 998824f58591be048bb95e05bc17de12be7bb56b --hard

 


 

 

reset이 잘 되었는지 log 확인

 

git log


 

commit이 취소가 되었고

git reset에서 설정한 버전 ID가 최신 인 것을 확인할 수 있습니다.

codedragon@CODEMASTER MINGW64 /c/CodeLab/gitLab/hellogit (master)

$ git log

commit 998824f58591be048bb95e05bc17de12be7bb56b

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 18:22:17 2017 +0900

 

    modify tag and text

 

commit 7f927e16cdc2a907f63ec697fbeb722301bbea50

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 15:54:17 2017 +0900

 

    add style.css

 

commit ff0bdc49565a237e588929b411b92fa0457b63ad

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 15:33:31 2017 +0900

 

    add code Hello git

 

commit a84948dab0005a6bca808f945fc6648cfe7243c8

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 15:32:23 2017 +0900

 

    add index.html

 

codedragon@CODEMASTER MINGW64 /c/CodeLab/gitLab/hellogit (master)

$

 

 


반응형

'Development > Git, PM' 카테고리의 다른 글

완성된 오픈소스 다운받기  (0) 2017.06.24
충돌을 막는 팁(git으로 협업시 팁)  (0) 2017.06.17
A Visual Git Reference  (0) 2017.05.18
git 기본 필수 명령어  (0) 2017.05.12
GitLab - 설치형 Github  (0) 2017.05.06