나미-IT 2022. 2. 16. 17:40

사용 툴 : vs code/ sourcetree

 

git add .

git commit -m "commit message"

 

--> git commit -am "commit message"  #위 두가지 한번에 , 단 새로 추가된 untracked(U) 파일 없어야 함

 

 

git diff

 

git log

 

** 되돌리기 (reset, revert)

reset 

git reset --hard <commit 번호>

git reset --hard -> 폴더를 commit한 타임캡슐 상태로 되돌림

 

**branch

git branch <new branch name> # branch 생성

git branch  #branch 목록 확인

git switch <branch-name> #branch로 switch

git switch -c new-teams #브랜치 생성과 동시에 이동하기

 

**branch 내역 graphical 하게 보기 

git log --all --decorate --oneline --graph

(그냥 소스트리 보면 되긴 함)

 

**branch 수정내역 합치기

1) merge 2) rebase

merge: branch history 그대로 있고 합침

rebase: branch history 없이 가지를 그대로 main에다가 갖다붙여서 깔끔하게 히스토리 유지함

 

현 위치를 git switch로 붙일 브랜치에 위치시킨 뒤

git merge main #main으로 붙음

1) git rebase main #main 뒤로 branch에 있던 히스토리가 붙음(주의: main 싹은 앞에서 멈춰 있음)

2) main 브랜치로 이동 후 

git merge new-teams #main을 new-teams에다가 합침(이러면 main과 new-branch가 모두 동일 위치(가장 최신)으로 붙게 됨)

 

**branch간 충돌 해결하기

git merge --abort

git merge --continue

git rebase --abort

git rebase --continue

 

git branch -d conflict-1

git branch -d conflict-2

 

 

 

Vim mode

i : 입력

esc: 빠져나오기

j: 위

k: 아래

:wq 저장하고 종료

:q! 저장 안하고 그냥 종료

 

 

https://www.youtube.com/watch?v=1I3hMwQU6GU 

https://www.yalco.kr/@git-github/2-1/