변경내용을 만들기 위해 index.html 파일을 수정하여 두 개의 commit 생성하기

CODEDRAGON Development/Git, PM

반응형

 

 

revert는 커밋한 역순으로 실행해야만 충돌이 발생하지 않습니다.

 

 

변경내용을 만들기 위해 index.html 파일을 수정하여 개의 commit 생성하기

 

 

index.html 파일에 1 내용 추가

 

1


 

git diff

git commit -am 'add 1'


 

 

 

index.html 파일에 2 내용 추가

 

2


 

git diff

git commit -am 'add 2'


 

 

 

변경사항 확인하기

 

git log -p

 


 

 

"modify tag and text" 상태로 revert 하려면 최신 커밋부터 역순으로 revert를 해야 합니다.

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

$ git log -p

commit f1acc6481c804581e4cc68d293c9ec66ab37ad88

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:21:38 2017 +0900

 

    add 2

 

diff --git a/index.html b/index.html

index 9ffd9e9..4c397b6 100644

--- a/index.html

+++ b/index.html

@@ -8,5 +8,6 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

+       2

 </body>

 </html>

\ No newline at end of file

 

commit 3ba7052eb1a1dc5df32b735e72711578016d076d

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:19:07 2017 +0900

 

    add 1

 

diff --git a/index.html b/index.html

index b29f5d7..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -7,5 +7,6 @@

 </head>

 <body>

        <h3>Hello World Hello git</h3>

+       1

 </body>

 </html>

\ No newline at end of file

 

commit 998824f58591be048bb95e05bc17de12be7bb56b

Author: codedragon <codedragon@tistory.com>

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

 

    modify tag and text

 

diff --git a/index.html b/index.html

index 04d85e6..b29f5d7 100644

--- a/index.html

+++ b/index.html

@@ -6,6 +6,6 @@

 <title></title>

 </head>

 <body>

-       <h1>Hello git</h1>

+       <h3>Hello World Hello git</h3>

 </body>

 </html>

\ No newline at end of file

 

commit 7f927e16cdc2a907f63ec697fbeb722301bbea50

Author: codedragon <codedragon@tistory.com>

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

 

    add style.css

 

diff --git a/index.html b/index.html

 

 


"add 2" 버전 revert하기

"git revert" 명령을 수행하면 commit 메시지 작성을 위한 창이 오픈되며 해당 vim창을 닫으면 commit이 수행됩니다.

 

git revert f1acc6481c804581e4cc68d293c9ec66ab37ad88

 

"add 2"커밋을 revert하겠다(Revert "add 2") commit이 자동으로 작성되어져서 나옵니다.

추가적인 정보가 필요하면 작성하면 됩니다.


 

종료하기

:wq


 


 

 

revert가 잘되었는지 변경 사항 확인하기

 

git log -p


 

새로운 커밋이 추가되었으며 revert시 작성된 commit 메시지가 표시된 것을 확인할 수 있습니다.

"add 2" 커밋에서 추가했던 내용이 삭제된 것을 확인할 수 있습니다.(- 2)

그 밑에 보면 "add 2" 커밋 내용은 그대로 남아있는 것을 확인할 수 있습니다.

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

$ git log -p

commit 2432717507498a1bd867b754662002d144dc58e1

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:27:01 2017 +0900

 

    Revert "add 2"

 

    This reverts commit f1acc6481c804581e4cc68d293c9ec66ab37ad88.

 

diff --git a/index.html b/index.html

index 4c397b6..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -8,6 +8,5 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

-       2

 </body>

 </html>

\ No newline at end of file

 

commit f1acc6481c804581e4cc68d293c9ec66ab37ad88

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:21:38 2017 +0900

 

    add 2

 

diff --git a/index.html b/index.html

index 9ffd9e9..4c397b6 100644

--- a/index.html

+++ b/index.html

@@ -8,5 +8,6 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

+       2

 </body>

 </html>

\ No newline at end of file

 

commit 3ba7052eb1a1dc5df32b735e72711578016d076d

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:19:07 2017 +0900

 

    add 1

 

diff --git a/index.html b/index.html

index b29f5d7..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -7,5 +7,6 @@

 </head>

 <body>

        <h3>Hello World Hello git</h3>

+       1

 </body>

 </html>

 

 

"add 1" 커밋을 다시 revert하기 위해 "add 1" 커밋ID를 복사합니다.

commit f1acc6481c804581e4cc68d293c9ec66ab37ad88

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:21:38 2017 +0900

 

    add 2

 

diff --git a/index.html b/index.html

index 9ffd9e9..4c397b6 100644

--- a/index.html

+++ b/index.html

@@ -8,5 +8,6 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

+       2

 </body>

 </html>

\ No newline at end of file

 

commit 3ba7052eb1a1dc5df32b735e72711578016d076d

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:19:07 2017 +0900

 

    add 1

 

diff --git a/index.html b/index.html

index b29f5d7..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -7,5 +7,6 @@

 </head>

 <body>

        <h3>Hello World Hello git</h3>

+       1

 </body>

 

 

"add 1" 커밋 revert 하기

git revert 3ba7052eb1a1dc5df32b735e72711578016d076d

 


 

commit 로그를 작성하는 화면이 나오면 :wq VIM을 종료합니다.

 

:wq


 



 

 

revert가 잘되었는지 변경 사항 확인하기

 

git log -p


 

"Revert "add 1"" 커밋 메시지와 함께 되돌리기 되어 졌다는 것을 알 수 있으며

코드를 보면 추가된 1이 빨간색 -로 표시되어 삭제된 것을 확인 할 수 있습니다.(- 1)

"<h3>Hello World Hello git</h3" 내용만 담고 있는 index.html 상태로 되돌리기 되었습니다.

커밋의 역순으로 되돌리기를 수행해야 충돌이 발생하지 않습니다.(주의)

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

$ git log -p

commit 715416d49440d0c2455d44621046b418a939f6e9

Author: codedragon <codedragon@tistory.com>

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

 

    Revert "add 1"

 

    This reverts commit 3ba7052eb1a1dc5df32b735e72711578016d076d.

 

diff --git a/index.html b/index.html

index 9ffd9e9..b29f5d7 100644

--- a/index.html

+++ b/index.html

@@ -7,6 +7,5 @@

 </head>

 <body>

        <h3>Hello World Hello git</h3>

-       1

 </body>

 </html>

\ No newline at end of file

 

commit 2432717507498a1bd867b754662002d144dc58e1

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:27:01 2017 +0900

 

    Revert "add 2"

 

    This reverts commit f1acc6481c804581e4cc68d293c9ec66ab37ad88.

 

diff --git a/index.html b/index.html

index 4c397b6..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -8,6 +8,5 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

-       2

 </body>

 </html>

\ No newline at end of file

 

commit f1acc6481c804581e4cc68d293c9ec66ab37ad88

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:21:38 2017 +0900

 

    add 2

 

diff --git a/index.html b/index.html

index 9ffd9e9..4c397b6 100644

--- a/index.html

+++ b/index.html

@@ -8,5 +8,6 @@

 <body>

        <h3>Hello World Hello git</h3>

        1

+       2

 </body>

 </html>

\ No newline at end of file

 

commit 3ba7052eb1a1dc5df32b735e72711578016d076d

Author: codedragon <codedragon@tistory.com>

Date:   Sat Feb 4 19:19:07 2017 +0900

 

    add 1

 

diff --git a/index.html b/index.html

index b29f5d7..9ffd9e9 100644

--- a/index.html

+++ b/index.html

@@ -7,5 +7,6 @@

 </head>

 <body>

        <h3>Hello World Hello git</h3>

+       1

 </body>

 </html>

\ No newline at end of file

 

commit 998824f58591be048bb95e05bc17de12be7bb56b

Author: codedragon <codedragon@tistory.com>

:

 

 

 

index.html 파일 내용 확인하기

"<h3>Hello World Hello git</h3>" 내용만 담고 있는 index.html 상태로 되돌리기 되었습니다.

cat index.html

 


 

 

반응형