git_ws % git clone https://zerobasegit:ghp_yazM0qurHSbS7wVeQcFEDJQPRX3Mgzus @github.com/zerobasegit/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 Unpacking objects: 100% (3/3), done.
(중간에 git hello.py는 오타임)
git_ws % cd log_project
log_project % cat > hello.py
print('hello, world')
log_project % git add hello.py
log_project % git commit -m 'create' hello.py
[main 01c9205] create
1 file changed, 1 insertion(+)
create mode 100644 hello.py
log_project % cat > hello.py print('hello, cat') log_project % git commit -m "modify 1" hello.py [main 23cd33c] modify 1 1 file changed, 1 insertion(+), 1 deletion(-)
log_project % git checkout -b dev Switched to a new branch 'dev' log_project % git branch * dev main
log_project % cat > hello.py print('hello, dog') log_project % git commit -m "modify 2" hello.py [dev 7347c01] modify 2 1 file changed, 1 insertion(+), 1 deletion(-)
git log
log_project % 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)
log_project % git log # # main 에서 git log 했기 떄문에 아래는 main의 log # # Initial commit > create > modify 1 아래부터 위로 순서대로 나옴 # # commit 다음에 오는건 버전넘버 # Date, Author, commit 버전넘버 등이 나옴 # commit 23cd33c423fdbf9759c1a0923a0a2bc51beb2fd2 (HEAD -> main) Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:35:05 2021 +0900 modify 1 commit 01c920522ae2dccc7205a6d31a0333854816bc66 Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:31:22 2021 +0900 create commit ee811c4ec1f2da8d345ae59f440b400e382f968b (origin/main, origin/HEAD) Author: zerobasegit <93780130+zerobasegit@users.noreply.github.com> Date: Sun Nov 7 20:24:55 2021 +0900 Initial commit
log_project % git checkout dev Switched to branch 'dev'
# 위 main 의 log 이력 + modify 2 까지 나온다. # log_project % git log commit 7347c01ea5fef07a249a1657bf7900de78a6b7d6 (HEAD -> dev) Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:39:42 2021 +0900 modify 2 commit 23cd33c423fdbf9759c1a0923a0a2bc51beb2fd2 (main) Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:35:05 2021 +0900 modify 1 commit 01c920522ae2dccc7205a6d31a0333854816bc66 Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:31:22 2021 +0900 create commit ee811c4ec1f2da8d345ae59f440b400e382f968b (origin/main, origin/HEAD) Author: zerobasegit <93780130+zerobasegit@users.noreply.github.com> Date: Sun Nov 7 20:24:55 2021 +0900 Initial commit
git config --global core.editor
(기본 에디더가 vim 이다)
git config --global core.editor <editorname> --wait
git config --global -e
(vscode로 열림)
위에서 --wait 옵션: 위 캡처 마지막에 file... 으로 되어있으면서 그 아래로는 vscode가 꺼질 때까지 더이상 다른 작업을 못하게 해놓음
[diff] tool = vscode [difftool "vscode"] cmd = "code --wait --diff $LOCAL $REMOTE"
(복붙해서 넣고 Ctrl + s )
현재 dev Branch 에는 'hello, dog'
master Branch 에는 'hello, cat'
git diff <branch1> <branch2>
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')
log_project % git difftool main dev Viewing (1/1): 'hello.py' Launch 'vscode' [Y/n]? y
git diff <commithash> <commithash>
log_project % git log commit 7347c01ea5fef07a249a1657bf7900de78a6b7d6 (HEAD -> dev) Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:39:42 2021 +0900 modify 2 commit 23cd33c423fdbf9759c1a0923a0a2bc51beb2fd2 (main) Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:35:05 2021 +0900 modify 1 commit 01c920522ae2dccc7205a6d31a0333854816bc66 Author: zerobasegit <zerobase.git@gmail.com> Date: Sun Nov 7 20:31:22 2021 +0900 create commit ee811c4ec1f2da8d345ae59f440b400e382f968b (origin/main, origin/HEAD) Author: zerobasegit <93780130+zerobasegit@users.noreply.github.com> Date: Sun Nov 7 20:24:55 2021 +0900 Initial commit
(modify 1 의 Hashcode 76721367f4a18e51dd94b1cd.....
commit의 Hashcode 78e9c16cdf2e186dff3d2a3f7c15...)
log_project % git difftool 01c920522ae2dccc7205a6d31a0333854816bc66 23cd33c423fdbf9759c1a0923a0a2bc51beb2fd2 Viewing (1/1): 'hello.py' Launch 'vscode' [Y/n]? y
# ^가 이전이란 뜻 git diff HEAD HEAD^ git difftool HEAD HEAD^
log_project % git difftool HEAD HEAD^ Viewing (1/1): 'hello.py' Launch 'vscode' [Y/n]? y
세팅
git diff HEAD
log_project % cat > hello.py print('hello, pig') log_project % git difftool HEAD Viewing (1/1): 'hello.py' Launch 'vscode' [Y/n]? y
git diff <branch> origin/<branch2>
log_project % git push origin main Counting objects: 6, done. Delta compression using up to 8 threads. Compressing objects: 100% (4/4), done. Writing objects: 100% (6/6), 553 bytes | 553.00 KiB/s, done. Total 6 (delta 0), reused 0 (delta 0) To https://github.com/zerobasegit/log_project.git ee811c4..23cd33c main -> main
log_project % git commit -m "modify 3" hello.py [main a9f87e0] modify 3 1 file changed, 1 insertion(+), 1 deletion(-)
log_project % git difftool main origin/main Viewing (1/1): 'hello.py' Launch 'vscode' [Y/n]? y
log_project % code .
• 이름 : diff_project
• 옵션 : README.md
• 위치 : git_ws 폴더
• text.txt
• 파일 내용 : my name is noma.
(diff_project 이동 후 작성)
(마지막에 Ctrl + d 두번해서 저장하고 빠져나옴)
(1) git add text.txt
(2) git status
(3) git commit -m 'create text.txt' text.txt
(4) git status
(5) git push origin main 여기서 깃허브에 생성됨
• 파일 수정 : my name is zero.
(1) ls
(2) cat text.txt 내용 확인
my name is noma.
(3) cat > text.txt
my name is zero. 내용수정
(Ctrl + d 두번 해서 저장)
(4) cat text.txt 수정한 내용 확인
my name is zero.
git commit -m 'modify name -zero' text.txt
git difftool main origin/main
(local은 my name is zero.)
(remote는 my name is noma.)
(Branch간 비교를 하려는 것)
• Branch 이름 : dev
• 파일 수정 : my name is base. (commit)
git checkout -b dev
• 두번째 Commit Message : create test.txt
• 마지막 Commit Message : modify name - base
(아래에서부터 위로 순서임)
(마지막 Commit Message : modify name - base)
(두번째 Commit Message : create test.txt)
(두번째, 마지막의 commit 값을 복사해줌)
git difftool 두번째 commit 값 마지막 commit 값
• VSCode 에서 diff_project 의 Git Graph 를 Branch 별로 확인
(diff_project 폴더에서 code . 해서 vscode 실행함)
위 글은 제로베이스 데이터 취업 스쿨의 강의자료를 참고하여 작성되었습니다.