git - newlife-js/Wiki GitHub Wiki
git init
git config user.name ' '
git config user.email ' '
git clone <리포지터리 url> <디렉터리>
git remote add <리포지터리 이름>(내가 원하는 대로, 기본은 origin) <리포지터리 url>
git push -u <리포지터리 이름> <branch 이름>
-u(--set-upstream) : remote repository에 branch를 생성하고 local branch가 remote branch를 tracking하도록 설정
git branch <branch 이름> // branch 생성
git switch <branch 이름> // branch 이동
git branch -d <branch 이름> // branch 삭제
checkout은 HEAD를 이동하는 역할
HEAD : git 사용자의 현재 위치
HEAD만 해당 commit으로 이동(detached HEAD상태가 됨)
해당 commit에서 새로운 branch를 만들어 사용할 때 보통 사용함.
git checkout <commit id>
git checkout -b <새로운 branch 이름> <commit id> // 새로운 branch도 만들어줌
git checkout -B <branch 이름> <commit id> // 이미 존재하는 branch를 해당 commit으로 reset(변경사항 있으면 -f로 강제할 수 있음)
HEAD가 해당 branch가 있는 commit으로 이동
git checkout <branch 이름>
git checkout -b <새로운 branch 이름> // 지금 HEAD에 새로운 branch만들어서 attachg
git checkout -f -B <branch 이름> <원하는 branch 이름(remote도 가능)>
// 기존에 존재하는 branch를 원하는 branch로 이동
git reset --soft // working directory, staging area 유지
git reset --mixed // working directory 유지, staging area reset
git reset --hard // working directory, staging area reset
working space(directory)의 변경 사항을 staging area(index)에 올리기
git add <파일명>
git add . // 수정사항 있는 모든 파일 올리기
git restore <파일명> // 수정 사항 되돌리기
git reset <파일명> // stage된 파일 다시 내리기
staing area에 있는 변경사항을 local repository에 올리기
git commit -m "메시지"
git commit --amend -m "메시지, Change-Id: <change id>"
// 기존 커밋을 push하기 전에 수정한 내용 함께 commit
// amend를 하지 않으면 여러 개의 commit이 올라가게 된다.
local repository를 remote repository로 올리기
git push <repository 이름> <local branch 이름>:<remote branch 이름>
git push <repository 이름> <local branch 이름>:refs/for/<remote branch 이름>
// gerrit에서 코드 리뷰를 받기 위해서는 refs/for/를 같이 입력해주어야 함.
remote branch의 initial revision은 parent commit의 id
remote repository의 변경 사항 가져오기
가져오기만 함
git fetch | <repository 이름>
가져와서(fetch) 현재 HEAD에 merge
git pull | <repository 이름> <local branch 이름>:<remote branch 이름>
현재 branch에 다른 branch의 변경사항을 합치기
git merge <다른 branch 이름>
자동 commit을 방지하기 위해서는 --no-commit 옵션을 추가하면 된다.
이 경우에는 해당 파일에 conflict내용이 저장되어 있는데, conflict된 내용을 처리한 후 저장한다.
그 후에 staging -> commit -> push를 해주어야 remote repository에 merge가 반영된다.
변경 사항을 임시 저장소(stack)에 저장
git stash save // 저장
git stash apply // 불러오기
작업 중이던 내용을 commit하지 않고 다른 branch에서 작업할 때,
작업 중이던 branch에 pull을 할 때 conflict 해결을 위해 (stash save -> pull -> stash apply -> conflict 파일 수정(merge conflict과 같은 방식) -> 해결)