Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

개발공부일지

Git ② - Branch, merge, rebase 본문

ETC

Git ② - Branch, merge, rebase

보람- 2023. 8. 21. 14:13

목차

1. Branch 만들기

2. branch 합치기

① merge

② rebase

3. Learn Git Branchig


 

1. branch 만들기

git branch [만들 브랜치 이름]
git branch develop

#새로 만든 branch 이동하기
git switch develop

 

※branch 옵션

# 브랜치를 생성함과 동시에 이동하는 옵션
git switch -c feature/board
git switch -c hoifix/board

# 브랜치 삭제
git branch -d hotfix/board

# 브랜치 이름 바꾸기 move
git branch -m feature/board feature/comment

 

 

 

2. branch 합치기

 

① merge

git merge [브랜치명]

- branch develop과 feature/comment를 합치는 경우

   - 병합 이슈가 없다면 commit이 만들어지고 끝이난다.

   - 만약 merge conflict이 생긴다면, 커밋이 만들어지지 않고 작업폴더에 이슈를 알려준다.

     문제는 직접 본인이 해결한 다음 stating영역에 넣어주고, git merge --continue 를 해주어야 한다.

-  merge를 하면 commit이 하나 더 생겨난다.

 

 

 

② rebase

git rebase [브랜치명]

- branch develop과 master를 합치는경우

   - rebase는 줄기가 사라지면서 한줄로 합쳐지게된다.

   - 주로 브랜치가 많아져 정리가 필요할때 rebase를 사용한다.

 

  •  rebase -i 옵션

git rebase -i [커밋해시값]

※ 명령어

- p, pick : 커밋 그대로 사용하기

- r, reword : 커밋 메세지 변경하기

- e, edit : 수정하기

- s, squash : 이전 커밋과 합칠때 사용

 

 

 

 

3. Learn Git Branchig

# 커밋 갖고놀기1
git rebase -i HEAD~2
git commit --amend
git rebase -i HEAD~2
git branch -f main

# 커밋 갖고놀기2
git switch main
git cherry-pick C2
git switch -f mian HEAD^
git cherry-pick C2 C3

# GIT TAG
git tag v0 C1
git tag v1 C2
git checkout C2

# GIT 묘사 describe 
git describe main 
v1_2_gC2 
-> main에 태그 v1 있고,2는 그태그가 몇 커밋 멀리있는지 알려주고 , 현재해시값C2
태그는 가장 가까운 부모태그를 나타낸다.


# 9천번이 넘는 리베이스
git switch bugFix
git rebase -i main
git switch side
git rebase -i bugFix
git switch another
git rebase -i side
git branch -f main another

or

git rebase main bugFix
git rebase bugFix side
git rebase side another
git rebase another main


# git 다수의 부모
git checkout HEAD~
git checkout HEAD^2
git checkout HEAD~2

= > git checkout HEAD~^2~2

git branch bugWork HEAD~^2~

# 브랜치 스파게티
git rebase main one
git rebase -i two
git rebase one two
git rebase -i three
git branch -f three C2
git switch one
git branch -f one HEAD^
git branch -f three C2

or 

git checkout one
git cherry-pick C4 C3 C2
git checkotu two
git cherry-pick C5 C4 C3 C2
git branch -f three C2

 


git init 를 하면 브랜치 하나가 꼭 생성되는데(main or master ) 그곳에 커밋이 쌓이고 있는것!

     → 하나의 프로세스에 스레드가 있는것과 같아

 

git branch 입력하면 *표시로 내가 현재 사용하고있는 branch를 알려준다!

git branch 입력했을 때의 화면

 

※ git clone 할때 디렉토리 확인하기 (.git 디렉토리 영역에 만들지않기!!!! 주의!!)

git clone https://github.com/ingoo-blockchain/rebase_sample

 

※ git flow 참고하기

https://techblog.woowahan.com/2553/

 

'ETC' 카테고리의 다른 글

Github - Pull requests, forks  (0) 2023.08.23
Github - Repositories, token,  (0) 2023.08.22
Git ① - git workflow, git add, git commit  (0) 2023.08.18
Linux ② - User , Shell, Process, Package Manager  (1) 2023.08.17
AWS , PuTTY , FileZilla, apache  (0) 2023.08.16