Git 07. Log and Diff

Jasmine·2023년 6월 8일
0

Git

목록 보기
4/7

Git Graph

실습환경 만들기

깃허브에서 log_project Repository 만든 후
로컬로 clone 해와서
log_project 에서 아래처럼 명령어 입력 진행

- cat <filename> 
	: 파일 내용 읽어오기
- cat > <filename>
	: 파일에 내용 덮어쓰기
- cat >> <filename>
	: 파일에 내용 추가하기

Git Log

Git log

Branch별 변경이력을 볼 수 있음
해당 branch로 이동(git checkout) 후 로그 확인(git log)

git log

Git Editor 설정

Git Editor 설정

--wait 옵션은 command line 으로 VSCode 를 실행시켰을 경우,
VSCode 인스턴스를 닫을 때까지 command 를 대기

git config --global core.editor <editorname> --wait
$ git config --global core.editor "code --wait"
$ git config --global core.editor "vim"
# esc : 명령모드
# i : 편집모드(insert)
# 명령모드에서 q! 하면 빠져나와짐

Git Diff Tool 설정

버전 간에 차이점을 확인할 수 있는 툴

Git Configuration 파일 열기

git config --global -e

Git Diff 설정 추가

열린 vscode의 git configuration 창에서 내용 추가하고 끄기 (다시 git bash로 돌아감)

[diff]
	tool = vscode
[difftool "vscode"]
	cmd = "code --wait --diff $LOCAL $REMOTE"

Git Diff

Git Diff - Local Branch 간 비교

git diff <branch1> <branch2>

실습1 - git bash (git diff)

log_project % git diff main dev
diff --git a/hello.py b/hello.py
index 0fd4867..96b5a66 100644
--- a/hello.py
+++ b/hello.py
@@ -1 +1 @@
-print('hello, cat')
+print('hello, dog')

실습2 - vscode (git difftool)

log_project % git difftool main dev
Viewing (1/1): 'hello.py'
Launch 'vscode' [Y/n]? y

Git Diff - Commit 간 비교

git diff <commithash> <commithash>

Commit Hashcode 확인

: git log 했을 때 commit 뒤의 문자열

create 과 modify 1 비교

log_project % git difftool 01c920522ae2dccc7205a6d31a0333854816bc66
 23cd33c423fdbf9759c1a0923a0a2bc51beb2fd2
Viewing (1/1): 'hello.py'
Launch 'vscode' [Y/n]? y

Git Diff - 마지막 Commit 과 이전 Commit 비교

git diff HEAD HEAD^
log_project % git difftool HEAD HEAD^
Viewing (1/1): 'hello.py'
Launch 'vscode' [Y/n]? y

Git Diff - 마지막 Commit 과 현재 수정사항 확인

git diff HEAD
log_project % cat > hello.py 
print('hello, pig')
# 아직 commit 하기 전 현재

log_project % git difftool HEAD
Viewing (1/1): 'hello.py'
Launch 'vscode' [Y/n]? y

Git Diff - Local 과 Remote 간 비교

git diff <branch> origin/<branch2>

Git Graph 확인

현재 폴더를 VSCode 로 열기 위해 아래와 같은 명령어 입력

log_project % code .

혼자 해봅시다

  1. GitHub 에서 Remote Repository 생성
    • 이름 : diff_project
    • 옵션 : README.md

  2. Local 에 Clone
    • 위치 : git_ws 폴더

git clone ~~
  1. Local Repository 에서 파일 생성 후 Push
    • text.txt
    • 파일 내용 : my name is noma.
cat > text.txt
my name is noma.

git add text.txt

git commit -m 'create text.txt' text.txt

git push origin main
  1. Main Branch 에서 파일 수정 후 마지막 commit 한 내용과 비교
    • 파일 수정 : my name is zero.
cat > text.txt
my name is zero.

git difftool HEAD
>> noma, zero
  1. Main Branch 에서 수정한 내용을 commit 한 뒤 Remote Server 와 비교
git commit -m 'modify name - zero' text.txt

# commit 후, push 전

git difftool main origin/main
>> zero, noma
  1. Dev Branch 생성 후 이동, 파일을 수정한 뒤 Master Branch 와 비교
    • Branch 이름 : dev
    • 파일 수정 : my name is base. (commit)
git checkout -b dev

cat > text.txt
my name is base.

git add text.txt

git commit -m 'modify -base' text.txt

git difftool main dev
>>zero, base
  1. Dev Branch 에서 두번째 commit 과 마지막 commit 비교
    • 두번째 Commit Message : create test.txt
    • 마지막 Commit Message : modify - base
(dev branch에서)
git log
>> hashcode 확인

git difftool 52821742166059d409a310affb30da2aa433376a 8e824fb063a62d73772ed62318e4968f911daa07 
>> noma, base
  1. Git Grpah 확인
    • VSCode 에서 diff_project 의 Git Graph 를 Branch 별로 확인
code .

> source control
profile
데이터직무를 위한 공부 기록

0개의 댓글

관련 채용 정보