[Day11] Git add,commit 구조 파악하기

🦥 add commit 구조파악

  • 여기 디렉토리에 .gitignorea.txt 가 있다.
    [vagrant@host1 bitcamp-ncp]$ ls -al
    total 8
    drwxrwxr-x. 3 vagrant vagrant   49 Nov 21 05:58 .
    drwxrwxr-x. 4 vagrant vagrant   46 Nov 21 05:27 ..
    -rw-rw-r--. 1 vagrant vagrant    6 Nov 21 05:58 a.txt
    drwxrwxr-x. 7 vagrant vagrant  119 Nov 21 05:35 .git
    -rw-rw-r--. 1 vagrant vagrant 3593 Nov 21 05:55 .gitignore
    
  • status를 조회하면 아직 add로 추가 해주지 않았기 때문에 아래와 같이 나온다.
    [vagrant@host1 bitcamp-ncp]$ git status
    # On branch master
    #
    # Initial commit
    #
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #       .gitignore
    #       a.txt
    nothing added to commit but untracked files present (use "git add" to track)
    
  • 이제 .gitignore 파일 하나만 git add를 추가하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git add .gitignore
    [vagrant@host1 bitcamp-ncp]$ git status --short
    A  .gitignore  <=== add한 파일에 A_가 생긴다
    ?? a.txt      <=== a는 add하지 않았기 때문에 ??로 작업 디렉토리에 남는다
    
  • 이 상태에서 commit 1번을 실행하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git commit -m "1"
    [master (root-commit) 281f094] 1
     1 file changed, 216 insertions(+)
     create mode 100644 .gitignore
    [vagrant@host1 bitcamp-ncp]$ git status --short
    ?? a.txt <=== add를 한 gitignore는 staged 상태가되었고
            <=== add를 하지않은 a.txt는 작업 디렉토리에 남아있다
    
  • 그리고 nano 편집기로 b.txt를 추가하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ nano b.txt
    [vagrant@host1 bitcamp-ncp]$ cat b.txt <===출력 명령어
    1111
    [vagrant@host1 bitcamp-ncp]$ git status --short
    ?? a.txt 
    ?? b.txt <===add 전 작업 디렉토리에 b.txt가 생겼다
    
  • a.txt를 add 하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git add a.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    A  a.txt <=== a.txt가 add 상태가 되었다
    ?? b.txt <=== add 하지 않았기 때문에 작업상태
    
  • commit 2번째를 실행하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git commit -m "2"
    [master 86f2e90] 2
     1 file changed, 2 insertions(+)
     create mode 100644 a.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    ?? b.txt <===add한 a.txt는 staged 상태가 되었다
    
  • staged된 a.txt파일을 nano로 다시 편집하고 status를 확인한다.
[vagrant@host1 bitcamp-ncp]$ nano a.txt
[vagrant@host1 bitcamp-ncp]$ cat a.txt
1111
2222
[vagrant@host1 bitcamp-ncp]$ git status --short
 M a.txt <=== _M상태가 되면서 파일을 변경했다는 표시가 뜬다
?? b.txt
  • _M a.txt는 남겨두고 b.txt를 add 한다.
    [vagrant@host1 bitcamp-ncp]$ git add b.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
     M a.txt
    A  b.txt <=== b.txt 가 add 된 상태
    
  • commit 3번째를 실행하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git commit -m "3"
    [master de6fcda] 3
     1 file changed, 1 insertion(+)
     create mode 100644 b.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
     M a.txt <=== add한 b가 staged된 상태
    
  • 여기서 다시 nano편집기로 b.txt를 편집한다.
    [vagrant@host1 bitcamp-ncp]$ nano b.txt
    [vagrant@host1 bitcamp-ncp]$ cat b.txt
    1111
    2222
    [vagrant@host1 bitcamp-ncp]$ git status --short
     M a.txt 
     M b.txt <=== 그전에 수정한 a.txt와 같은 상태가 되었다
    
  • 다시 add를 통해 a.txt를 추가하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git add a.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    M  a.txt <=== M_표시로 바뀌고 stated 상태로 만들었다 
     M b.txt
    
  • 다시 commit을 4번째로 실행 시키고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git commit -m "4"
    [master 1498aed] 4
     1 file changed, 1 insertion(+)
    [vagrant@host1 bitcamp-ncp]$ git status --short
     M b.txt <=== add를 하지않은 b.txt만 남은 상태
    
  • 이제 add로 _M b.txt를 추가하고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git add b.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    M  b.txt <===전 단계의 a.txt와 같은 모습
    
  • commit 실행전 다시한번 nano편집기로 수정한다.
    [vagrant@host1 bitcamp-ncp]$ nano b.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    MM b.txt <=== staged 상태의 파일을 또 수정한 경우 MM으로 볼수있다
    
  • 이 상태에서 commit 5번째를 실행한다
    [vagrant@host1 bitcamp-ncp]$ git commit -m "5"
    [master 99d7c27] 5
     1 file changed, 1 insertion(+)
    [vagrant@host1 bitcamp-ncp]$ git status --short
     M b.txt 
    
  • add로 b.txt를 실행시키고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git add b.txt
    [vagrant@host1 bitcamp-ncp]$ git status --short
    M  b.txt <=== commit하기에 알맞은 상태가 됨
    
  • commit 6번째를 실행시키고 status를 확인한다.
    [vagrant@host1 bitcamp-ncp]$ git commit -m "6"
    [master 7d61aa4] 6
     1 file changed, 1 insertion(+)
    [vagrant@host1 bitcamp-ncp]$ git status --short
    이제 모든 디렉토리가 commited 상태가 되었기 때문에 아무것도 나오지 않는다
    
  • git log 확인
    commit 7d61aa41dcda75ab206d2a335d3ac3cfc4beac3e <===hash값
      6  <=== 최신순 commit 으로 출력
      .
      .
      1
    
  • commit 최근 2개 출력 git log -p -2

  • log 한줄로 출력 git log --oneline
    [vagrant@host1 bitcamp-ncp]$ git log --oneline
    7d61aa4 6 <=== hash 값과 함께 짧게 출력
    .
    .
    281f094 1
    

    Windows 에서 hash 값 확인하기

  • certutil -hashfile 파일명.zip SHA512

Leave a comment