DevOps 실현을 위한 CI/CD 구축 (22.05.31)

박민선·2022년 6월 6일
0

Git

저장소 만들기

버전관리를 하지 않는 로컬 디렉토리

mkdir mygit
cd mygit
git init

기존 Git 저장소 클론

git clone <URL>

Git 프로젝트의 세 가지 상태

파일의 생명주기

상태 확인

git status

스테이징

git add <FILE>
git add .

.gitignore 파일

  • 아무것도 없는 라인이나, #로 시작하는 라인은 무시한다.
  • 표준 Glob 패턴을 사용한다. 이는 프로젝트 전체에 적용된다.
  • 슬래시(/)로 시작하면 하위 디렉토리에 적용되지(Recursivity) 않는다.
  • 디렉토리는 슬래시(/)를 끝에 사용하는 것으로 표현한다.
  • 느낌표(!)로 시작하는 패턴의 파일은 무시하지 않는다.

Staged와 Unstaged 상태 변경 내용 보기

staged 상태가 아닌 파일 비교

git diff

커밋과 staged 상태 비교

git diff --staged

변경사항 커밋(버저닝, 스냅샷)

git commit

기본 에디터 변경
git config --global core.editor <EDITOR>

인라인 메시지

git commit -m <MESSAGE>

스테이징 및 인라인 메시지

git commit -a -m <MESSAGE>

좋은 Commit 메시지

https://gist.github.com/robertpainsi/b632364184e70900af4ab688decf6f53

파일 삭제

rm <FILE>

삭제한 파일 Staged 상태

git rm <FILE>

파일명 변경

git mv <ORGION> <NEWFILE>

커밋 히스토리/로그

git log

로그 출력 변경
git config --global core.pager 'less'
git config --global core.pager ''

git log --oneline

수업 중 예제

1) vi pod.yaml 파일 생성 후
2) git add pod.yaml or .(전체 파일 add)
3) git status 상태확인

4) git config 정보 등록

git config --global user.email "ypjs09@gmail.com"
git config --global user.name "Suny-1030"
git config --global --list


5)git commit message 확인

git commit -m "create config"   
  #-m 으로 상태창에 진입하지 않고 바로 commit message를 작성할 수 있음

git log
git log --oneline     # 한줄로 로그 확인 가능

6) 이전 버전으로 돌아가기

git checkout

7) 최근 상태로 돌아가기

git checkout master

8) 파일명 변경

git mv pod.yaml mypod.yaml

9) 기존 commit mesage 사용

git commit --amend

HEAD -> 바라보는 곳

10) branch 이용

git branch dev1 
git checkout dev1
git log 


11) branch dev1 에서 새로운 yaml파일을 구성하여 add/commit

git log --oneline --graph   #변경된 HEAD의 위치를 확인

12) branch 삭제

git branch -d dev1
git branch -D dev1   # 강제삭제

13) branch 생성

git checkout -b dev2   # 없는 branch 생성 후 이동

14) git 병합

git merge dev2

merge의 충돌
다른 branch에서 같은 파일의 같은 라인을 수정 하여 병합하면 충돌이 일어남

15) branch name 변경하기

git branch -M main    #사용중일 때는 m 을 못씀

16) remote 하기

git remote add origin https://github.com/Sunny-1030/effective-eureka.git

17) push 하기

git push -u origin main

username sunnuy-1030
password *****
(만약 이중인증이면 토큰 발급을 해야함)

만약 github에서 직접 수정을 하면
(fetch -> fast-forward)
git fetch origin

18) fast-forward

git merge origin/main
(fast-forward)

github 협업시
세팅 -> collaborators -> add people
(많은 collaborator는 x)
Fork -> 다른사람의 레포지터리를 가져올 수 있다

19) tag 생성

git tag -a 'v0.1' -m 'Version 0.1'
git tag -l
git push origin v0.1

20) ssh key 등록하기

ssh-keygen

cat id_rsa.pub 복사

github에 붙여넣기

git 간편안내서

참고링크: https://rogerdudler.github.io/git-guide/index.ko.html

profile
클라우드신생아

0개의 댓글