[Git] Rebase

Judy·2023년 1월 21일
0

Dev

목록 보기
5/7
post-custom-banner

MERGE & REBASE

  • Both of these commands are designed to integrate changes from one branch into another branch
  • They just do it in very different ways.

https://gitforteams.com/resources/merge-rebase.html

Merge problems

! Create unnecessary merge commit

  • In every feature branch, there are “merge commit”.
  • What if there are many developers who share the main branch and the size of the project is large?
  • Branch history can be noisy.
    (= Even if a logic is created and modified in an independent branch, it becomes difficult to distinguish between other tasks and their history.)

Rebase

! Clean up unnecessary merge commit

! Gathering commits that have done the same work

Rebase changes the base of commit
= Organize the commit history in a line.
To check the base commit of the branch : git merge-base main feature/sign-in (Not necessary)

Rebase Process

1. Rebase - Before push the branch to main…

git pull origin main
git checkout feature/branch
git rebase -i main

2. Squash

Commit Message Cleanup && Integration

  1. pick : Pick the base point commit

  • Based on which commit do you clean up other commit?
  • Pick the oldest commit!
  • top → bottom === oldest → latest
  • It does not mean that other commit's work history will be lost.
  1. s : Squash commits

  2. :wq

3. Resolving conflict in rebase

  • Conflict can occurs when the contents are different between Commit.
  • During the rebase, many commits can raise conflict at once.
  • If a conflict occurs, the rebase does not proceed or end, it just stops in the middle.
  • 👍 On terminal, we can see a message (rebase 1/2 ~1) that inform us rebase is in progress.
  1. Resolve conflict
  2. save file
  3. git add .
    git commit (Don’t do commit!)
  4. git rebase —-continue
  5. You can see first commit message. :wq
  1. repeat 1-5 until rebase finished
    If you can't resolve conflict, rollback it git rebase --abort

4. Last step of rebase

  • Finally, write the commit messsage of this rebased commit.
  • It shows all the commit messages that we've written so far.
  • Clean up the unnecessory messages and write the commit message about the rebase
  • :wq

5. Successfully rebased !

Check commit message usning git log

6. Push after rebase

git push origin [branch] -f (force push)

  1. Rebase cleans up the commit history
  2. Commit history can be changed when we rebase on the same branch
  3. Commit history is changed when we modify code and rebase it
  4. git does not allow pushing of branches with different histories.
profile
NLP Researcher
post-custom-banner

0개의 댓글