cat hell.py
: hell.py
의 내용을 보여달라cat > hell.py
: hell.py
이 존재한다면 내용을 덮어쓰고, 없다면 만들고 내용을 써라cat >> hell.py
: 꺽쇠 2번이면 붙여쓴다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(-)
- 처음 만들때 hello, world 로 만들고 commit
- main에서 commit을 한 상태에서 내용을 hello, cat 으로 수정함
- dev 라는 Branch를 만든 다음에 hello, dog 으로 수정함
요약하자면 main은 modify 1 까지의 이력이 있어야 하고, dev는 modify 2 까지의 이력이 있어야 한다.
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 Editor 설정
--wait
옵션은 git command로 인해서 vscode를 실행할 때 그 command가 대기 상태로 있다가 vscode를 다 사용하고 닫는 순간에 완료가 된다
git config --global core.editor <editorname> --wait
Git Configuration 파일 열기
git config --global -e
[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>
git diff <commithash> <commithash>
-> modify 1 의 Hashcode 76721367f4a18e51dd94b1cd.....
commit의 Hashcode 78e9c16cdf2e186dff3d2a3f7c15...
# ^가 이전이란 뜻
git diff HEAD HEAD^
git difftool HEAD HEAD^
git diff HEAD
git diff <branch> origin/<branch2>
일단 현재 Main Branch 상태를 Remote Repository 로 Push
log_project % git commit -m "modify 3" hello.py
[main a9f87e0] modify 3
1 file changed, 1 insertion(+), 1 deletion(-)
• 이름 : 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
Remote Server 와 비교(push 전)
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
<아래에서부터 위로 순서>
3. 마지막 Commit Message : modify name - base
2. 두번째 Commit Message : create test.txt
1. 두번째, 마지막의 commit 값을 복사해줌
• VSCode 에서 diff_project 의 Git Graph 를 Branch 별로 확인