• Blog
  • Projects
  • Resume
profile_image

[Git] 삽질의 추억 - 스쿼시커밋

Git

2021.05.02

학원에서 예전에 했던 프로젝트를 다시 이어서 작업할 일이 있어 방법을 찾다가 쓰게된 글
스쿼시 커밋을 안했다면.. 내 예전 커밋로그는 어디로 ㅠㅠ

작업로그



1. 이렇게 하니 PR이 안됨..

# clone
$ git clone -b Rano --single-branch https://github.com/17-sss/fe-w5-searchUI.git
$ cd fe-w5-searchUI\

# 이전 3주차 쇼핑하우 저장소 remote
$ git remote add shoppingHowOrigin https://github.com/17-sss/fe-w3-shopping.git
$ git remote -v

# 이번 미션 5주차용 첫 branch 생성 (searchUI-step1)
$ git checkout -b searchUI-step1

# 3주차 미션의 마지막 브랜치 pull
$ git pull shoppingHowOrigin shoppinghow-step5

# 이번 미션의 로컬저장소에 3주차 미션의 마지막 브랜치 기반으로 브랜치 생성
$ git checkout -b shoppinghow-step5 --track shoppingHowOrigin/shoppinghow-step5

# rebase할 브랜치로 checkout (최종 기준이 되는 branch)
$ git checkout searchUI-step1

# rebase: rebase 재료를 써줌
$ git rebase shoppinghow-step5

# conflict 수정
$ git add .
$ git rebase --continue

# upstream 설정 및 Push
$ git remote add upstream https://github.com/codesquad-members-2021/fe-w5-searchUI.git
$ git push --set-upstream origin searchUI-step1

2. PR 가능하도록 다시 작업

# clone
$ git clone -b Rano --single-branch https://github.com/17-sss/fe-w5-searchUI.git
$ cd fe-w5-searchUI\

# 이전 3주차 쇼핑하우 저장소 remote
$ git remote add shoppinghow https://github.com/17-sss/fe-w3-shopping.git
$ git remote -v

# 이번 미션 5주차용 첫 branch 생성 (searchUI-step1)
$ git checkout -b searchUI-step1

# 3주차 미션의 마지막 브랜치 pull
$ git pull shoppinghow shoppinghow-step5 --allow-unrelated-histories

# confilct 해결 후
$ git add .
$ git commit

# upstream 설정 및 Push
$ git remote add upstream https://github.com/codesquad-members-2021/fe-w5-searchUI.git
$ git push --set-upstream origin searchUI-step1

# 하나의 커밋으로 합치기위해 rebase
$ git rebase -i 7094f2af    # git rebase -i [기준점 커밋ID]
<Typography variant="h3" backgroundColor="gray">
  <span>최상단에 있는 commit 로그는 pick으로. 나머지는 s(squash)로.</span>
</Typography>
  ## 달라질 수 있음

# confilct가 있다면 해결 후
$ git add .
$ git rebase --continue      # 커밋 로그 수정

# 마지막으로 --force push
$ git push origin searchUI-step1 --force



참고 자료