Git - Log and Diff

jaam._.mini·2024년 1월 2일
0

💻 GIT

목록 보기
2/5
post-thumbnail

Log and Diff ... ?

Git Graph 설치


new (file + branch)


  • 기본 set

    PC@DESKTOP-7USISEH MINGW64 ~
    $ cd Documents/
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents
    $ cd git_ws/
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
    $ git clone https://JaeminOh94:[토큰]@github.com/JaeminOh94/log_project.git
    Cloning into 'log_project'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Receiving objects: 100% (3/3), done.
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
    $ ls
    HelloGit/  branch_project/  exam_project/  log_project/  test_project/
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws
    $ cd log_project/
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $
    
  • 아래 쿼리 + enter + ctrl+d(저장>다음칸)

    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ cat > hello.py
    print('hello world')
  • 출력

    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ cat hello.py
    print('hello world')
    
  • add ~ commit 전까지

    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
            hello.py
    
    nothing added to commit but untracked files present (use "git add" to track)
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git add hello.py
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    Changes to be committed:
      (use "git restore --staged <file>..." to unstage)
            new file:   hello.py
  • Commit + VS Code (Git Graph)

    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git commit -m 'create' hello.py
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    [main 411897e] create
     1 file changed, 1 insertion(+)
     create mode 100644 hello.py
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ cat hello.py
    print('hello, world')
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ cat > hello.py
    print('hello, cat')
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git commit -m 'modify 1' hello.py
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    [main 5f5d1e5] modify 1
    1 file changed, 1 insertion(+), 1 deletion(-)
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ code .
    

  • git checkout -b [어쩌구]

    • main > dev 로 바뀜
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
    $ git checkout -b dev
    Switched to a new branch 'dev'
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev) 📌
    $
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
    $ git branch
    * dev
      main
    
  • new Branch

    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
    $ cat hello.py
    print('hello, cat')
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
    $ cat > hello.py
    print('hello, dog')
    
    PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
    $ git commit -m 'modify 2' hello.py
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    warning: in the working copy of 'hello.py', LF will be replaced by CRLF the next time Git touches it
    [dev fee74ca] modify 2
     1 file changed, 1 insertion(+), 1 deletion(-)

Git Log


Branch 별 변경이력 을 볼 수 있음

  • (1) main Branch 로 이동
PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
$ git checkout main
Switched to branch 'main'
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
$ git log
commit 5f5d1e51ffb3a191d1b7b0ad0e985876fb62b0be (HEAD -> main)
Author: JaeminOh94 <94woals@naver.com>
Date:   Wed Jan 3 01:11:16 2024 +0900

    modify 1

commit 411897ec38dc4015380597c4687aecefe30c4a86
Author: JaeminOh94 <94woals@naver.com>
Date:   Wed Jan 3 01:08:37 2024 +0900

    create

commit e18fb84d4bdf493840bf0e6fffe9c02b23b81288 (origin/main, origin/HEAD)
Author: JaeminOh94 <155232890+JaeminOh94@users.noreply.github.com>
Date:   Wed Jan 3 00:54:00 2024 +0900

    Initial commit

PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
$

PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (main)
$ git checkout dev
Switched to branch 'dev'

PC@DESKTOP-7USISEH MINGW64 ~/Documents/git_ws/log_project (dev)
$ git log
commit fee74cad03e7cbfc647408b42265c8788def1411 (HEAD -> dev)
Author: JaeminOh94 <94woals@naver.com>
Date:   Wed Jan 3 01:16:55 2024 +0900

    modify 2

commit 5f5d1e51ffb3a191d1b7b0ad0e985876fb62b0be (main)
Author: JaeminOh94 <94woals@naver.com>
Date:   Wed Jan 3 01:11:16 2024 +0900

    modify 1

commit 411897ec38dc4015380597c4687aecefe30c4a86
Author: JaeminOh94 <94woals@naver.com>
Date:   Wed Jan 3 01:08:37 2024 +0900

    create

commit e18fb84d4bdf493840bf0e6fffe9c02b23b81288 (origin/main, origin/HEAD)
Author: JaeminOh94 <155232890+JaeminOh94@users.noreply.github.com>
Date:   Wed Jan 3 00:54:00 2024 +0900

    Initial commit

Git Editor 설정


Git Diff


(1) Git Diff Tool 설정

버전 간의 차이점을 확인할 수 있게 해줌

  • Git Configuration 파일 열기

    • global 로 설정된 editor를 수정하겠다
    git config --global -e

  • Git Diff 설정 추가

    [diff]
        tool = vscode
    [difftool 'vscode']
        cmd = 'code --wait --diff $LOCAL $REMOTE'
  • Local Branch 비교
    2 Branch 최신 버전의 차이를 보여 줌

      git diff <branch1> <brnach2>
      git difftool main dev

  • Commit 간의 비교

    git diff <commithash> <commithash>


  • 마지막 Commit 과 이전 Commit 비교

    git diff HEAD HEAD^(마지막 바로 전)

  • 마지막 Commit과 현재 수정사항 확인

    git diff HEAD

  • Local - Remote 비교

    git diff <branch> origin <brnach2>

  • Git Graph 확인
profile
비전공자의 데이터 공부법

0개의 댓글