Infra/git

GIT merge

2022. 6. 21. 22:10
반응형

merge 란?

  • git merge는 다른 브랜치를 현재 Checkout된 브랜치에 Merge 하는 명령으로, Merge 하고 나서 현재 브랜치가 Merge 된 결과를 가리키도록 옮긴다.

merge 명령어

  • 서로 다른 branch 병합 하기
git checkout {branchA}
git merge {branchB}  //A에 B 변경 내역을 병합
git merge --continue // 병합 저장
git merge --abort // 병합 롤백
  • 특정 브랜치에서 file 1개만 merge 하기
git checkout {branchA} {filename}  //A branch 에서 file 1개 merge
반응형

'Infra > git' 카테고리의 다른 글

GIT rebase  (0) 2022.06.21
GIT push  (0) 2022.06.21
GIT commit  (0) 2022.06.21
GIT stash  (0) 2022.06.21
GIT clean  (0) 2022.06.21

GIT rebase

2022. 6. 21. 22:07
반응형

rebase

  • 서로 다른 두브랜치를 병합시킬 때
  • 여러개의 commit 이력을 1개의 새로운 commit 으로 합칠 때(되감기)
    • git merge 전략 중 하나.
    • 내가 작업한 브랜치에 master의 최신 이력을 적용시킬 때(브랜치 현행화)
    • 개인 브랜치는 commit history 깔끔하게 관리하고 싶을 경우 수행 추천.
    • 공동 작업 브랜치 or master에는 수행하지 말자(remote master에 merge된 경우 기존의 commit tree가 완전히 달라지기에 동료들로 부터.....)

rebase 활용

  1. feature 브랜치에서 작업을 하는 동안 main 브랜치가 release, hotfix 등 변경되었고 merge 하려 할 때 충돌이 발생, feature 브랜치에서 main 브랜치를 rebase 진행한 후 main으로 merge를 수행한다.
  2. main 브랜치의 내용을 현재 작업 중인 feature 브랜치로 병합할 때(최신 commit으로 base 옴겨주기)
git rebase -i HEAD~2,3 //합칠 개수
git rebase -i HEAD~3 //마지막부터 몇번째 commit 까지 개수
​
 pick -> squash 변경 후 vi 저장 //합칠경우 (lastest 부터 역순으로!!!!)
 pick -> drop 변경 후 vi 저장   //특정 commit 삭제
​
git log //합쳐진 commit 확인 or git reflog
git commit -m "주석 수정" //합친 후 주석 수정 or 새로운 commit 안남길 경우 건너뜀
git rebase --continue //rebase 완료  
git rebase --abort //rebase 롤백시 
git push origin {branch} -f //force remote push
  • rebase invalid upstream 'HEAD~n' 오류 발생시 처리
git rebase --interactive HEAD~5   //위 순서에 맞춰 vi 편집 후 force push
반응형

'Infra > git' 카테고리의 다른 글

GIT merge  (0) 2022.06.21
GIT push  (0) 2022.06.21
GIT commit  (0) 2022.06.21
GIT stash  (0) 2022.06.21
GIT clean  (0) 2022.06.21

GIT push

2022. 6. 21. 22:04
반응형

push

local repository에 commit 이력을 remote branch 로 보낼 경우 사용

git push origin {branch}
git push origin {branch} -f  // remote force push

최근 commit 이력을 취소하고 push(remote에 잘못된 commit 이력을 push 했을 경우)

git reset HEAD^ 
git push origin master -f

commit history 전부 삭제하고 초기 상태로 되돌릴 경우

rm -rf .git 
git init 
git add . 
git commit -m "feat(init): initial commit" 
git push origin master
반응형

'Infra > git' 카테고리의 다른 글

GIT merge  (0) 2022.06.21
GIT rebase  (0) 2022.06.21
GIT commit  (0) 2022.06.21
GIT stash  (0) 2022.06.21
GIT clean  (0) 2022.06.21

GIT commit

2022. 6. 21. 22:02
반응형

commit

  • 작업 중인 파일 내역 저장 (원격 저장소 push 전 수행)
  • 작업시 기능 단위로 나눠서 #commit 하면 코드 리뷰 시 리뷰어가 보기 편함
git commit -m "commit init"
git commit --amend  //message vi 모드
git commit --amend -m "메세지 변경"  //message 변경
git reset HEAD^ or git reset {commit id} //local commit 취소
git commit --allow-empty -m "empty commit"  //empty commit
반응형

'Infra > git' 카테고리의 다른 글

GIT rebase  (0) 2022.06.21
GIT push  (0) 2022.06.21
GIT stash  (0) 2022.06.21
GIT clean  (0) 2022.06.21
GIT restore  (0) 2022.06.21

GIT stash

2022. 6. 21. 22:00
반응형

stash

  • workspace에서 수정 중인 파일 임시 저장
  • 작업 중 #브랜치 전환할 경우 수정 중인 파일 임시로 저장 후 스위칭시 유용함
git stash save {stashname}
git stash list  //목록 보기
git stash clear  // 전체 삭제
git stash apply stash@{0}  //저장된 stash 불러오기
git stash pop  //가장 마지막에 save한 stash 불러오기
반응형

'Infra > git' 카테고리의 다른 글

GIT push  (0) 2022.06.21
GIT commit  (0) 2022.06.21
GIT clean  (0) 2022.06.21
GIT restore  (0) 2022.06.21
GIT add  (0) 2022.06.21

+ Recent posts

반응형