참고: 생활코딩 지옥에서 온 GIT
Git init
(경로) repository 생성/초기화
(--bare) 원격 저장소를 생성
Git add
modify된 파일을 stage 상태로
Git status
staging area에 대한 정보를 알려줌
Git commit
staging 된 파일을 repository에 버전 업데이트
(-a) unstage 된 파일을 포함하여 모두 commit, 단 add된 이력이 있는 파일만
(—amend) 최신 commit msg를 수정
Git log
현재 branch의 commit 역사를 보여줌
(-p) 시간순으로 각 commit 간의 변경사항을 알려줌
(--branches) 모든 branch 의 commit 을 보여줌
(--graph) graph 의 형태로 보여줌
(--oneline) commit을 한줄로 보여줌
(--all) 모두 보여줌
(branch1..branch2) branch1엔 없고 branch2에 있는 commit을 보여줌
Git diff
staging area와 working copy의 차이를 보여줌
(commit id 1..commit id 2) 1과 2의 차이를 보여줌
Git reset
(--soft) repository를 해당 commit 상태로 reset
(--mixed) index와 repository를 해당 commit 상태로 reset / git reset 의 기본 옵션
(--hard) working directory, index와 repository를 해당 commit 상태로 reset / commit 주소를 주지 않으면 자동으로 최신 commit으로 설정됨
Git revert
reset과는 다르게 중간의 commit 만 취소할 수 있음
revert 를 하게되면 revert 한 commit이 base가 되어 3way merge가 일어난다.
Git branch
현재 branch를 알려줌
(branch) branch를 생성
(-d branch) 해당 branch 를 삭제
Git checkout
(branch) branch로 checkout
(-b branch) branch 생성 + checkout
Git merge (branch)
현재 branch로 (branch) 병합
(--no--ff) fast forward가 가능함에도 그 방식으로 병합하지 않겠다는 옵션
(branch)의 조상에 현재 branch가 포함되어 있을 경우 Fast-forward방식으로 병합
Fast-forward 방식으로 병합되게 되면 새로운 commit 없이 현재 branch가 (branch)를 가리키는 방식으로 병합
Fast_forward 방식이 아닌 merge 는 위의 경우 이외의 경우이며 3way merge를 통해 새로운 commit이 생성된다
3way merge는 공통조상, (branch), 현재 branch를 참고한 merge 방식
같은 파일의 같은 부분을 수정했을 경우 해당 파일은 unstaged (add를 해줘야한다)
Git stash
branch 작업 도중 commit 하지 않고 다른 branch로 넘어가 작업할때 사용. 단, 변경된 파일은 tracked 상태(한번이라도 add된 이력이 있는) 여야함
(apply) 가장 최근 stash를 적용
(drop) 가장 최근 stash 를 list에서 삭제
(list) 저장된 stash list를 보여줌 0번부터 최근 stash
(pop) apply+drop
Git remote add origin 주소
주소에 해당하는 origin이라는 원격 저장소 등록
Git remote
원격저장소 보기
(-v) 상세보기
Git push (--set-upstream | -u) origin master
git push 할때마다 master를 origin이라는 원격 저장소에 자동으로 push 하겠다. 초기 한번만 해주면 됨
Git clone 주소 폴더명
폴더를 생성하고 주소의 source를 clone
Git tag (tag_name) (branch | commit id)
tag 생성
(-a) tag의 annotation 을 하고싶을때 (-m “~”)
(-v) tag의 정보를 알고 싶을때
(-d) 삭제
++ git push --tags를 해야 tag까지 push 됨
Git rebase (branch)
merge 는 commit history를 병렬적으로 합치지만, rebase의 경우 이를 직렬적으로 합쳐줌. rebase를 하게 되면 현재 branch의 fetch(각각의 commit의 변경사항)를 순차적으로 (branch)에 적용하며, conflict가 나게 되면 conflict를 해결하고 git rebase --continue를 하여 rebase작업을 계속할 수 있다. rebase가 끝나게 되면 현재 checkout 한 branch의 가지가 삭제되고 rebase가 끝난 시점의 최신 commit으로 branch가 이동되게 된다. (commit이 삭제되는 것은 아니다)
Index(cache)
staging area 에 현재 등록된 파일의 이름과 그 파일의 내용의 주소를 담고있다
Object
blob, tree, commit으로 구성되어 있다
blob : 파일의 내용을 담고 있다
tree : 폴더의 정보를 담고 있다
commit : 해당 commit 의 상태(tree), 직전의 commit(parent), author, committer, msg를 담고 있다
Git add
추가한 파일의 내용에 해당하는 blob object 가 없다면 blob object를
추가하고 index 를 현재 staging area와 동기화 한다
Git commit
commit object를 생성하고 이전의 commit object가 존재하면 해당 주소로
parent 를 추가한다
Git status
최신 commit 의 파일 내용과 working directory의 파일 내용을 비교하여
modified 여부를 확인하고 working directory와 index 를 비교하여 staged
여부를 확인한다
Git branch (branch)
refs/heads/(branch) 가 생성되고, 최신 commit을 가리키게 됨
Git checkout (branch)
HEAD 파일의 내용이 refs : refs/heads/(branch) 로 바뀜
Git reset
ORIG_HEAD : 어떤 위험한 명령을 하기전에 현재 branch의 주소를 저장, git reset —hard ORIG_HEAD를 통해 최근 reset을 취소 할 수 있음
logs/refs/heads/master : master가 가리키는 주소의 변화 역사를 보여줌, 명령어로는 git reflog를 통해 확인할 수 있음, 주소 옆에 있는 HEAD@{?}로도 가능 ?가 낮을수록 최신의 것
3way merge
HEAD, ancestor, branch 를 비교하여 merge하는 방식
3개의 내용이 모두 같을 경우 -> 그대로
elif 3개의 내용이 모두 다를 경우 -> conflict
else anscestor 과 다른 것을 반영
Git remote add origin 주소
.git/config 파일에 origin 이라는 원격 저장소의 주소를 저장
Git push -u origin master
.git/config 파일에 로컬 master branch와 origin이 연결된다는 정보를 저장
thenounproject 아이콘
Git tag
refs/tags/(tag_name) 이 추가되고 tag가 가리키는 commit id 가 저장됨
annotation을 추가하면 objects 폴더에 tag에 대한 정보가 저장됨
Git flow
Master : 사용자에게 배포되는/노출되는 branch
Hot fix : 긴급하게 수정되어야 할 사항이 있을 경우 생성. 완료 즉시 develop, master branch에 merge후 push
Release : develop branch에서 master branch로 가기전 최종 검수 단계. 변경사항이 있을경우 develop branch에 수시로 merge 후 push, 검수가 완료되면 develop, master branch에 merge 후 push
Develop : develop 이 진행되는 branch
Feature : 새로운 기능이 개발되는 branch 개발하는 과정에서 수시로 develop branch의 변경사항을 merge
-> git flow cheatsheet 참고
Git flow init
git flow 개시
Git flow feature start (feature_name)
feature branch를 만들고 checkout
Git flow feature publish (feature_name)
feature 의 remote branch를 만들고 push 해주고 해당 feature branch 로 checkout
Git flow feature finish (feature_name)
develop branch 로 merge
Git flow release start (release_name)
release branch 생성후 checkout
Git flow release finish (release_name)
main branch 와 병합 후 tag 설정, develop branch로도 병합
Git flow hotfix start (hotfix_name)
main branch에 hotfix branch 생성 후 checkout
Git flow hotfix finish (hotfix_name)
main branch 와 병합 후 tag 설정, develop branch로도 병합
name: {action_name}
on: [{events}]
Jobs:
build:
runs-on: {어떤 runner에서 동작시킬지}
steps: # event가 일어나면 아래의 작업을 순차적으로 수행하라
- uses: actions/{} # 이미 만들어놓은 action을 실행할때
- name : {실행의 이름}
env: # github에서 정의한 context를 사용할때
{환경변수 이름} : ${{ context }}
run: {command}