git revert, reset, commit --amend, rebase (git LT vol.3)

6237 단어 Git
회사 내부용 물건을 약간 개편하였다
주로 git 초급자를 겨냥한 내용입니다.
슬라이딩 모드로 보시면 좋을 것 같아요.

과거의commiit를 수정하고 싶어요!타임


카탈로그


아래 4 개 자주 사용
  • 1. git revert
  • 2. git reset
  • 3. git commit --amend
  • 4. git rebase
  • 자유로운 인상

  • 1. git revert-> 안전편 33!
  • 2. git reset-> 간단한 시도 33!
  • 3. git commit --amend->commiit log 교정 시 자주 사용하는 방법:!
  • 4. git rebase 정통파의 관점!
  • 중요
    1 이외에commiit의 역사적 왜곡 때문에
    이미push가 된commiit는 기본적으로 사용하지 않습니다

    1. git revert


    과거 commiit의 부정 commiit 다시 만들기

    1. git revert


    다음에 설명한 바와 같이 A, B, C와commiit를 진행하고 가장 가까운 C를 취소하고 싶을 때
    A -> B -> C

    1. git revert

    $ git revert HEAD(최신 commiit는 HEAD)
    A -> B -> C -> D
    D=C의 부정commiit
    commiit가 진행되었지만 상태가 B와 같습니다

    1. git revert


    주안점
    새로운 수정commiit 만들기 = 수정commiit는 역사에 남는다

    1. git revert


    GiitHub과 Azure DevOps에서 홍보를 하고 나서...
    revert 버튼이 나오네요.
    A -> B
    ↓ 홍보
    A -> B -> C
    ↓revert 버튼 누르기
    A -> B -> C -> D
    C가 알림을 받지 않았어요.

    1.git revert가 사용하는 곳

  • 이미push된commiit를commiit와 함께 삭제하고 싶을 때
  • 마스터에서.
    -> 장애 발생
    ->일단 돌려놔!
    이런 느낌이죠~
    겸사겸사 말씀드리겠습니다.$ git revert HEAD$ git revert @도 가능합니다.
    (@은 HEAD 별칭)

    2. git reset


    과거의commiit가 없음을 결정합니다

    2. git reset


    다음에 설명한 바와 같이 A, B, C와commiit를 진행하고 가장 가까운 C를 취소하고 싶을 때
    A -> B -> C

    2. git reset

    $ git reset HEAD~1(HEAD에서 이전 commiit까지의 상태)
    A -> B
    C 삭제
    하지만 C의 변경 부분은 손에 남는다(작업 트리)

    2. git reset --hard


    힘든 녀석들도 있고.$ git reset --hard HEAD~1(HEAD에서 이전 commiit까지의 상태)
    A -> B
    매장
    C의 변경 부분은 손에 남지 않습니다(작업 트리)

    2.git reset 사용 위치

  • 최근에 push가 없는commiit를 수정하고 싶을 때
  • 불필요한 파일이commiit
  • 에 의해
  • 불필요한 파일 병합
  • typo가 발견됐지만 새로운 commiit는 하고 싶지 않아요~
    잠깐만요?
  • 2.git reset-hard 사용 방법

  • commiit의 연쇄 반응이 무책임하게 파괴되었을 때 붕괴 전의 역사
  • 로 거슬러 올라갈 수 있다
  • merge나conflict를 통해 이해가 안 될 때 작업 중인 것stash(회피)를 먼저git pull을 가능하게 하려고 할 때
    잠깐만요?
  • 3. git commit --amend


    최근 commiit 변경

    3. git commit --amend


    다음처럼 A, B, C와commiit를 진행하고 C의commiit log의 typo를 수정할 때
    A 1st commit log
    B 2nd commit log
    C 3nd commit log
    ↑ 3rd!

    3. git commit --amend

    $ git commit --amend이렇게 치면 commiit log 입력 화면(vim 등)이기 때문에 3rd commiit로 바꾸어 저장하고 끝냅니다(: wq)
    A 1st commit log
    B 2nd commit log
    C 3rd commit log

    3. git commit --amend


    또한, 필요하지 않은 파일도commiit에서 사용할 수 있습니다
    gitrm에서 필요하지 않은 파일 삭제$ git rm unnecessary.txtgit commit --amend$ git commit --amend이렇게 치면 commiit log 입력 화면(vim 등)이기 때문에 3rd commiit로 바꾸어 저장하고 끝냅니다(: wq)

    3.git commiit--am end 사용 방법

  • 최근의commiit와commiit log를 쉽게 수정하고 싶을 때
  • 4. git rebase


    과거의commiit를 자유롭게 개편(무엇이든 할 수 있는 결말 33;)

    4. git rebase


    용도가 여러 가지가 있어요.
    제가 자주 쓰는 건 commiit를 깔끔하게 정리할 때예요.

    4. git rebase


    예를 들어 아래와 같이 A, B, C, D commiit와 B, C, D를 하나의 commiit로 정리하고 싶을 때.
    A -> B -> C -> D

    4. git rebase


    A -> B -> C -> D
    역사는 B 세 개로 거슬러 올라갈 수 있다$ git rebase -i HEAD~3

    4. git rebase


    편집 모드 들어가기
      1 pick 922348a A commit log
      2 pick 3b03490 B commit log
      3 pick a2e6bff C commit log
      4
      5 # Rebase fa4e3e0..a2e6bff onto fa4e3e0 (3 commands)
      6 #
      7 # Commands:
      8 # p, pick = use commit
      9 # r, reword = use commit, but edit the commit message
     10 # e, edit = use commit, but stop for amending
     11 # s, squash = use commit, but meld into previous commit
     12 # f, fixup = like "squash", but discard this commit's log message
     13 # x, exec = run command (the rest of the line) using shell
     14 # d, drop = remove commit
     15 #
     16 # These lines can be re-ordered; they are executed from top to bottom.
     17 #
     18 # If you remove a line here THAT COMMIT WILL BE LOST.
     19 #
     20 # However, if you remove everything, the rebase will be aborted.
     21 #
     22 # Note that empty commits are commented out
    

    4. git rebase


    B와 C의commiit log 앞쪽을 pick에서 s(squash)로 변경하여 저장하고 끝냅니다.
      1 pick 922348a A commit log
      2 s 3b03490 B commit log
      3 s a2e6bff C commit log
      4
      5 # Rebase fa4e3e0..a2e6bff onto fa4e3e0 (3 commands)
      6 #
      7 # Commands:
      8 # p, pick = use commit
      9 # r, reword = use commit, but edit the commit message
     10 # e, edit = use commit, but stop for amending
     11 # s, squash = use commit, but meld into previous commit
     12 # f, fixup = like "squash", but discard this commit's log message
     13 # x, exec = run command (the rest of the line) using shell
     14 # d, drop = remove commit
     15 #
     16 # These lines can be re-ordered; they are executed from top to bottom.
     17 #
     18 # If you remove a line here THAT COMMIT WILL BE LOST.
     19 #
     20 # However, if you remove everything, the rebase will be aborted.
     21 #
     22 # Note that empty commits are commented out
    

    4. git rebase


    이어서 commiit log 편집 모드로 들어갑니다
    이 정도면 보존하면 끝이야
        1 # This is a combination of 3 commits.
        2 # This is the 1st commit message:
        3 
        4 A commit log
        5 
        6 # This is the commit message #2:
        7 
        8 B commit log
        9 
       10 # This is the commit message #3:
       11 
       12 C commit log
       13 
       14 # Please enter the commit message for your changes. Lines starting
       15 # with '#' will be ignored, and an empty message aborts the commit.
       16 #
       17 # Date:      Wed Dec 5 10:10:14 2018 +0900
       18 #
    (以下略)
    

    4. git rebase


    A -> B -> C -> D
    농담하다
    A -> E
    되다
    E=B, C, D 포함

    4. git rebase


    git rebase가 심오해서 자세한 건 다음에 기회!
    나는 commiit log를 깨끗하게 유지하고 자신과 다른 개발자에게 부드러운 창고를 만들고 싶다!
    경청해 주셔서 감사합니다!

    좋은 웹페이지 즐겨찾기