해당 글은 제로베이스데이터스쿨 학습자료를 참고하여 작성되었습니다
깃허브 -> log_project 생성(README파일 포함) -> git clone -> 폴더로 들어가서 VScode 실행 -> VScode 확장팩 -> git graph 설치 -> git graph로 Log 확인
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ git clone https://InSung-Na:TOKEN@github.com/InSung-Na/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. HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws $ cd log_project/ HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (master) $ code .
cat file
: 파일 내용 확인cat > file
: 내용 덮어쓰기cat >> file
: 내용 이어쓰기ctrl D
: 저장HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (main) $ cat > hello.py print("hello, world") HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (main) $ cat hello.py print("hello, world") HPcom@DESKTOP-TJ3L1B9 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 HPcom@DESKTOP-TJ3L1B9 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 389d3d4] create 1 file changed, 1 insertion(+) create mode 100644 hello.py HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (main) $ cat > hello.py print("Hello, cat") HPcom@DESKTOP-TJ3L1B9 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 ffcfb54] modify 1 1 file changed, 1 insertion(+), 1 deletion(-)
HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (main) $ git checkout -b dev Switched to a new branch 'dev' HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (dev) $ cat hello.py print("Hello, cat") HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (dev) $ cat > hello.py print("Hello, dog") HPcom@DESKTOP-TJ3L1B9 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 a0af043] modify 2 1 file changed, 1 insertion(+), 1 deletion(-)
git log
- main과 dev에서 log 확인
HPcom@DESKTOP-TJ3L1B9 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) HPcom@DESKTOP-TJ3L1B9 MINGW64 ~/Documents/git_ws/log_project (main) $ git log commit ffcfb54210d7ebe636fa6174066fed994e5ed05a (HEAD -> main) Author: InSung-Na <lht98323@gmail.com> Date: Wed Feb 22 10:09:50 2023 +0900 modify 1 commit 389d3d45dd8577212c7cb6345bd6d11b1ec3eb33 Author: InSung-Na <lht98323@gmail.com> Date: Wed Feb 22 10:08:03 2023 +0900 create commit e4224862d9adcaec81acd6a4cdc9030ac5b7fac6 (origin/master, origin/main, origin/HEAD) Author: InSung-Na <118172599+InSung-Na@users.noreply.github.com> Date: Wed Feb 22 09:44:44 2023 +0900 Initial commit
git config --global core.eidtor "code"
git config --global -e
입력 후 생성되는 창에 아래 내용 입력
[diff]
tool = vscode
[difftool "vscode"]
cmd = "code --wait --diff &LOCAL $REMOTE"
git diff branch1 branch2
: bash에서 확인git difftool branch1 branch2
: 설정한 툴에서 확인git diff commithash1 commithash2
git difftool commithash1 commithash2
commithash는 git log
시 commit 뒤의 문자열
git diff head head^
git difftool head head^
git diff head
git difftool head
HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/log_project (main) $ git diff head head^ diff --git a/hello.py b/hello.py index c988194..9f69d32 100644 --- a/hello.py +++ b/hello.py @@ -1 +1 @@ -print("Hello, cat") +print("hello, world")
git difftool branch1 origin/branch2
HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/diff_project (main) $ git diff main origin/main diff --git a/test.txt b/test.txt index f239f1c..a8e0267 100644 --- a/test.txt +++ b/test.txt @@ -1 +1 @@ -my name is zero. +my name is noma.
git config --global -e
입력 후 생성되는 창에 아래 내용 입력
[merge]
tool = vscode
[mergetool "vscode"]
cmd = "code --wait $MERGED"
Merge : 현재 위치한 branch를 다른 branch을 병합
Merge Conflict : Merge, Push와 Pull 과정에도 충돌 발생가능
merge_project를 만들고 git clone
dev branch 생성
(main) cat > test.txt : my name is noma
(dev) cat >> test.txt : are you?
test.txt commit하기
HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (dev) $ git checkout main Switched to branch 'main' Your branch is up to date with 'origin/main'. HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main) $ git branch dev * main HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main) $ git merge dev Updating ad3d2d8..85de5c3 Fast-forward test.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main) $ git log commit 85de5c3d1be7e55d3e2d752558b35cf139616271 (HEAD -> main, dev) Author: InSung-Na <lht98323@gmail.com> Date: Wed Feb 22 12:48:58 2023 +0900 modify 1 commit ad3d2d8a5d441fba0e16b7b79dd04310ec096c33 (origin/main, origin/HEAD) Author: InSung-Na <118172599+InSung-Na@users.noreply.github.com> Date: Wed Feb 22 12:44:34 2023 +0900 Initial commit
HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main) $ git merge dev2 Auto-merging test.txt CONFLICT (content): Merge conflict in test.txt Automatic merge failed; fix conflicts and then commit the result.
git mergetool
입력시 vscode 열림git add file
+ git commit
입력
HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main|MERGING) $ git add test.txt HPcom@DESKTOP-TJ3L1B9 MINGW64 /C/Users/HPcom/Documents/git_ws/merge_project (main|MERGING) $ git commit [main 7b3c854] Merge branch 'dev2'
git commit
입력시 충돌 내용 보여줌