Git/Github 02

oching·2022년 4월 14일
0

Git

목록 보기
1/4

22.04.14 최우영 강사님

  • README.md
  • License
  • .gitignore
  • Branch
  • Git flow 전략
    되돌리기, 취소 시나리오
    모의 팀 프로젝트

복습 clone

cd documents  
cd dev 
git clone https://github.com/oching-choi/branch-practice.git
cd branch-practice
ls -al

README.md

# Project Name
Abstract your project in few lines.
see [project sample page](project link)

## Documentation

### Installation
To install,
`$ pip install sesame`
and run `$ python open_sesame.py`

### Supported Python versions
`>=3.6`

### More Information
- [API docs]()
- [Official website]()

### Contributing
Please see [CONTRIBUTING.md]()

### License
Sesame is Free software, and may be redistributed under the terms of specified in the [LICENSE]() file.

License

  • MIT License 제약, 특허권 책임 X

  • Apache License 2.0 특허권 명시 O

  • GNU General Public License v3.0
    가장 많이 알려져있으며, 의무사항(해당 라이센스가 적용된 소스코드 사용시 GPL
    을 따라야 함)이 존재.


.gitignore

Git 버전관리에서 제외할 파일 목록을 지정하는 파일
때문에 파일 생성 후 ls 해도 확인 불가함.
ls -a 로 확인가능.
개발환경에서 모듈의 과도한 트래킹 방지를 위해 주로 활용된다.

# 주석을 달기 위한 Hashtag

# MacOS Setup
.DS_Store

# Python cache files
.py[cdo]

# Important files
/Important

# AWS key
key.pem
vi .itignore


vi환경)
# Custom

Keyfile.pem
crendentials/**
secrets.*  //secret이 붙은 모든 확장자
*.java  //.java확장자 모든 파일 
vi환경 종료)

$ cat .gitignore  //vi에서 쓴 내용 확인


git status로 추적해봤을 때 .gitignore에서 정의한 파일은 추적하지않는다는 것을 확인할 수 있다.

gitignore.io

https://www.toptal.com/developers/gitignore/
사용하는 개발 환경을 적으면 ignore할 vi내용을 생성.

.git ignore commit하기

git add .gitignore
$ git status
$ git commit

vim환경)
 제목 convertion : conf 

branch

분기점을 생성하여 독립적으로 코드를 변경할 수 있도록 도와주는 모델

git branch  //존재하는 branch 확인
git branch print-hello   //print-hello 라는 branch 생성
git branch   //main ,print-hello 두개 확인됨
git checkout print-hello   //git 이동 
                           // 새버전에서 checkout대신 switch사용

touch hello.py  
vi hello.py

vi환경)
print('hello')
vi환경에서 저장후 나오기)

cat hello.py  //vi에 적은 내용확인

git status   //추적상황 확인
git add hello.py  //hello.py 추적 stage에 올리기
git status  //추적상황 확인
git commit  //commit하기

vi commit 환경)
제목 
내용 적기
vi commit 환경 저장후 나옴)

브랜치별로 생성된 파일을 커밋하면
다른 브랜치 이동 했을 때 해당 파일이 존재하지않음.

git switch main  //main으로 전환
ls  //hello.py가 없다
git switch print-helo   //print-helo branch로 전환
ls  //hello.py가 있음

branch merge

git switch main  //main으로 이동
git branch   //branch확인
git merge print-hello  //합병

branch 삭제

사용을 다 한 branch는 바로 삭제해주는 것이 좋다

$ git branch -D print-hello

conflict

branch 마다 각자 따로 작업이 이뤄진 후 병합한다면?

hello.py에서 if문

vi hello.py

vi 환경)
magin_num = 3
if magin_num =3
    print ('hello'):
vi 환경 종료)  


$ git status
$ git add hello.py
$ git status

$ git commit

$ git switch repeat-hello  //repeat-hello branch로 전환
vi hello.py 

vi 환경)
for _ in range(1,10+1):
    print ('hello'):
vi 환경 종료)  

$ cat hello.py

$ git status
$ git add hello.py
$ git status
$ git commit

vi commit환경)
제목, 내용 적음
vi 환경 - 저장하고 나옴)  

$ git switch main
git merge repeat-hello
이때 conflict발생   // repeat-hello 브랜치환경에서 수정이 발생했기때문

conflict 해결

충돌난 hello.py의 내용을 수정해준다.

vi hello.py

vi환경)
for i in range(1,10+1):
    if i%3==0:
        print ('hello')
git status


아직 unmerge
commit해야 merge된다

git commit


merge가 되면 위에 merge안내문구가 나옴


깃헙 입장에선
로컬main에서 원격main으로 push한 것이기에
원격main은 중간 branch가 있었다는 사실을 알수없다.

만약 중간branch가 있었다는 사실을 남겨야한다면
따로 나눠 push해야한다.

$ git switch repeat-hello

$ git push -u origin repeat-hello  
//remote에 없는 branch를 푸쉬할 땐 -u을 붙여야한다. 

모든 branch를 기록하듯 push해야하는 것은 아니지만
필요할 때 있음.

branch 모델

  • git flow
    (hotfix)- master -(release)- develop - feature
    master, develop 이라는 핵심브랜치가 두개
    pros: 가장 많이 적용, 각 단계가 명확히 구분
    cons: 체크아웃을 자주 해야해 복잡..
    현업에서 많이 사용됨

  • github flow
    핵심 브랜치하나
    다이렉트로 바로 릴리즈할 때 주로 사용
    master - feature
    pros: 브랜치 모델 단순화, master 의 모든 커밋은 deployable
    cons: CI 의존성 높음. 누구 하나라도 실수했다간..(pull request로 방지)

  • gitlab flow
    production - pre-production - master - feature
    pros: deploy, issue에 대한 대응이 가능하도록 보완
    cons: git flow와 반대 ( master -develop, production -master)


Gitflow strategy

feature branch 즉, 기능별 브랜치를 분기시켜 관리하는 전략.

https://danielkummer.github.io/git-flow-cheatsheet/index.ko_KR.html
git flow commend를 쉽게 다루게해주는 도구
MacOs는 따로 setup설정해야함.

gitflow commend

  • git flow 시작
    git flow init

  • git flow feature 브랜치 생성
    git flow feature start branch_name

  • git flow feature 브랜치 닫기
    git flow feature finish branch_name

  • git flow release 시작
    git flow release start v0.1

  • git flow release 종료
    git flow release finish v0.1
    commit창이 세개가 뜸

    1. Merge branch 'release/v0.1' - merge / 저장후 나감
    2. Write a message for tag: - 깃헙에서 확인되는 라벨링태깅 / 한 내용 적기
    3. Merge tag 'v0.1' into develop / 저장 후 나감
$ git flow init
Which branch should be used for bringing forth production releases?
   - main
Branch name for production releases: [main]
계속 enter로 prefix설치

$ git branch
// develop main 두개 확인됨 

$ git flow feature start print-world

$ git branch 
// develop feature/print-world main 이렇게 세개나옴
//내 현재 위치도 feature/print-world 브랜치에 와있음

vi hello.py  //hello.py내용수정
vi환경)
for i in range(1,10+1):
    if i%3==0:
        print ('{} hello'.format(i))
    elif i%5 ==0:
        print('{} world' .format(i)):
vi환경끝)

cat hello.py
git status
git add hellow.py
git status
git commit

vi commit환경)
feat : 으로 제목
vi commit 환경끝)


$ git flow feature finish print-world
//finish하면 아래 내용 확인됨
Switched to branch 'develop'
Updating 9da7e50..3f414e7
Fast-forward
 hello.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Deleted branch feature/print-world (was 3f414e7).

Summary of actions:
- The feature branch 'feature/print-world' was merged into 'develop'
- Feature branch 'feature/print-world' has been locally deleted
- You are now on branch 'develop'
//알아서 merge하고 deleted해준 것 까지 확인된다. 




$ git flow release start v0.1
//릴리즈하기
Switched to a new branch 'release/v0.1'

Summary of actions:
- A new branch 'release/v0.1' was created, based on 'develop'
- You are now on branch 'release/v0.1'

Follow-up actions:
- Bump the version number now!
- Start committing last-minute fixes in preparing your release
- When done, run:

     git flow release finish 'v0.1'
     
 git flow release finish v0.1
//commit창이 두개가 열림
1. Merge branch 'release/v0.1' - merge하는거 / 저장후 나감
2. Write a message for tag:  - 깃헙에서 확인되는 라벨링태깅 / 한 내용 적기
3.Merge tag 'v0.1' into develop / 저장 후 나감

버전관련 참고사항 )

  • 마이너체인지 새로운 기능의 추가 : 뒤에있는 숫자가 올라감
    ex) v0.1 -> v0.2
  • 메이저체인지 이전버전에서는 없던 아주 새로운 기능 : 앞에 있는 숫자가 올라감
    ex) v1.0 -> v2.0

버전은 0.1부터 시작임
아주 작은 단위의 수정은 세자리 수까지 주는 경우있음.

branch 명시 push

브랜치를 분기했다는 것을 깃헙이 알아볼 수 있게
따로 push 해야함

$ git push -u origin develop  //branch 첫 push는 -u
$ git push origin main
$ git tag
$ git --tags

알고리즘 공부 추천 사이트
https://leetcode.com/
https://www.hackerrank.com/
https://www.acmicpc.net/


  • 이름 바꾸기 (Rename)
    mv 현재이름 바꿀이름 -> delete sideeffect 발생
    git mv 현재이름 바꿀이름
현재위치 develop branch

mv README.md leadme.md


deleted 가 됨

$ git mv hello.py helloworld.md

git commit   //이름만 바꾸는 경우라 add해주지않았음. 

vi commit)
fix : Rename hello.pu to hellowoeld.py  
vi commit 끝)
  • 내용 수정 취소 (Undoing)
    git restore helloworld.md

  • add취소 (Unstaging)
    $ git reset HEAD helloworld.md

  • commit 내용 되돌리기
    없던 일 처럼
    git commit --amend

  • commit을 취소하기 (Reset)
    git reset --hard HEAD~n //현재 상태에서 n번째 전까지로 commit상태 취소
    commit을 완전 삭제한 후 remote에 강제 push함.
    중간이력이 사라져 협업시 commit log tracking이 힘들어짐.
    쓰는 것 지양할 것.

  • commit 되돌리기 (Revert)
    git revert --no-commit HEAD~N..


revert 사유는 commit에 꼭 자세히 이유를 적어두기

gitflow strategy 팀 모의 테스트 해보기

팀장)
repository개설
git flow init //gitflow 시작
git branch develop  //develop이라는 branch생성
touch 각팀원파일 
git status
git add 파일명
git status 
git commit 
git push -u origin develop


팀원)
issue확인 (할일, 버그리포트)
issue작성 - 내가 뭘 할 지 미리 공유  
##간단내용 
##task list
-do fizz
-do buzz
-do fizzbuzz
원본 링크 fork(복사해서 내 repo로 가져오게 준비) 
dev 경로에서 내게 할당된 fork clone
git flow init  //gitflow 시작
ls  //내가 작업할 파일 존재유무 확인
git flow feature start 파일명  //start
vi 파일명
vi환경에서 작업)  //vi작업
git status
git add 파일명  //onstaging
git status
git commit  //commit
git flow feature finish 파일명  //finish
git push -u origin develop 
git remote add upstream 원본주소  //pull
git pull upstream develop
profile
FE Studying

0개의 댓글