[ Log and Diff ]
[ git graph ]
- vscode -> git graph 검색, 설치
- Remote Respository 생성 (log_project 생성)
- git_ws 폴더의 Local Repository에 clone
- cd log_project
- cat > hello.py (새 파일 만들기)
- print('hello, world')
- git add hello.py
- git commit -m 'create' hello.py
- 위 log_project를 vscode로 열어서 그래프 확인
- cat hello.py: 파일 안에 담겨있는 내용을 출력함
- cat > hello.py: 입력한 내용으로 덮어쓴다.
- cat >> hello.py: 입력한 내용이 원래 있던 내용 아래에 추가된다.
- cat > hello.py => print('hello, cat')
- git commit -m 'modify 1' hello.py
- branch 생성 후 이동
- Master branch에서 수정하던걸 dev branch로 이동한 다음 하는 것!
- git checkout -b dev
- git branch
- cat > hello.py ==> print('hello, dog')
- git commit -m 'modify 2' hello.py
[ Git log ]
- git checkout master
- git log
[ Git editor 설정 ]
git_ws 폴더
- git config --global core.editor "code --wait"
git_ws 폴더
- git config --global -e
[diff]
tool = vscode
[difftool “vscode”]
cmd = “code —wait —diff $LOCAL $REMOTE”
추가 후 저장 & 닫기
[ Git diff ]
git diff <branch1><branch2> / git difftool <branch1><branch2>
-> git log
-> git diff(tool) <commithash><commithash>
-> git diff(tool) head head^
-> cat > hello.py
-> print(‘hello, pig’) + ctrl D
-> git diff(tool) head
-> 일단 현재 Master branch 상태를 remote repository 로 push
-> git push origin master
-> git commit -m “modify 3” hello.py
-> git diff(tool) master origin/master
-> code .
[ Merge & Conflict ]
[ 실습 환경 ]
- remote repository에서 merge_project 생성
- git_ws에서 local repository로 복제
- cd merge_project
- cat > test.txt -> my name is noma
- git add text.txt
- git commit -m “create” test.txt
- git checkout -b dev
- cat >> test.txt -> are you?
- git commit -m “modify 1” test.txt
- git log
- git_ws 폴더, branch는 Dev
- git config --global -e
[merge]
tool = vscode
[mergetool "vscode"]
cmd = "code --wait $MERGED" 추가
[ Merge ]
- 현재 위치한 branch에서 다른 branch를 병합
git merege <branchname>
- main branch의 test.txt 내용은 my name is noma.
- dev branch의 test.txt 내용은 my name is noma. are you?
- main branch 위치
- git merge dev
- cat test.txt -> main branch와 dev branch가 합쳐짐
- git log 확인
- code . (vscode 실행) -> graph 확인
[ Conflict ]
- Branch 를 Merge 하는 과정에서 충돌이 날 수 있음
- 혹은 Push, Pull 하는 과정에서도 충돌이 일어날 수 있음
- cat > test.txt -> hello, noma.
- git commit -m ‘reset’ test.txt
- Conflict test를 위한 branch 생성
- git branch dev2
- git branch
- cat > test.txt
- - git commit -m ‘modify -zero’ test.txt
- git checkout dev2
- cat test.txt -> (dev2에서는 hello, noma라고 되어있음.)
# 현재 main 과 dev2에서 같은 파일의 같은 라인 코드가 다른 상태
- cat > test.txt -> hello, base.
- git commit -m 'modify -base' test.txt
- git checkout main
# Dev2에서도 내용 수정
git merge dev2 -> conflict 발생!!
- git mergetgool (vscode 실행됨)
- 원하는 코드 (hello, base) 남기고 다 지우기
- 저장 & 끄기
- Conflict 해제
- conflict 상황을 해제하려면 add, commit 단계를 한번씩 거쳐야한다.
- git status로 확인
- git add test.txt
- git commit (vscode 실행됨)
- 저장 & 끄기
- cat test.txt 로 확인해보면 hello, base.로 바뀌어있음!
- merge가 된 것.
- git log로 확인
[ Tag ]
[ git Tag 실습 환경 ]
- Remote repository에서 tag_project 생성
- local로 Git clone
- cat > hello txt -> hello, world.
- add, commit1 실행
- cat > hello txt -> hello, noma.
- add, commit2 실행
- cat > hello txt -> hello, zerobase.
- add, commit3 실행
- git push origin main 으로 commit3 한 것을 remote repository로 옮김.
[ tag ]
- git tag v0.3
- git log로 확인
-> 특정 버전의 commit hash 필요
-> git tag v0.2 c91ece52d4853340bd4640679c6c5d5a656707d1
- git push origin v0.3
- git tag
- git show V0.2
- git tag —delete v0.3 (local에서 삭제)
- git push —delete origin v0.3 (remote에서도 삭제)
# remote에서만 삭제하고 local에서 삭제 안하기도 가능.
[ README ]
- README
- remote repository에서 수정 가능
- Markdown
- README의 가독성을 좋게 만들어주는 장치.
- remote repository에서 확인!