git cherry-pick과 rebase

정은경·2020년 1월 16일
0

cherry-pick

  • 다른 브랜치에 있는 commit 중에 원하는 commit만 쏙쏙 가져오는 것
  • branch b에 다가 branch a의 커밋 a1, a2, a3 중에 a3을 가져오고 싶다면, 아래와 같이 실행한다
checkout branch b
git cherry-pick a3

rebase


            ↗ m1 -> m2 :master 브랜치
a -> b -> c 
            ↘ t1 -> t2 :topic 브랜치
  • master와 topic의 공통 base는 commit "c"
  • master의 브랜치를 topic 브랜치로 rebase한다는 것은, 아래와 같이 변경하는 것
a -> b -> c -> t1 -> t2 -> m1 -> m2 :master 브랜치
                    :topic 브랜치
git checkout master
git rebase topic


merge vs. rebase

  • merge는 m2와 t2를 병합하여 mt3버전을 생성
  • rebase는
    • m1과 t2 워킹카피를 병합하여 m1을 생성
    • m2와 m1을 합쳐서 m2를 생성
    • 주의!! m1, m2가 원격 저장소에 push되지 않고 로컬에 있을 때만이 rebase 가능!
  • 결론적으로 merge 결과 생성된 mt3와 rebase결과 생성된 m2는 서로 같음! 같은 결과물! (다만, 과정이 다를뿐!)

git working copy?!

cherry-pick 충돌 원인/해결


(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify⚡) » git commit -m "wip"
[Feature/Artwork-model-modify 6e8cf44] wip
 Committer: MarieJung <marie@MarieJungui-MacBookPro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

pick e790a5f modify artwork.models
# This is a combination of 6 commits.
After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 20 files changed, 4363 deletions(-)
 delete mode 100644 artists.csv
 delete mode 100644 artwork_colors.csv
 delete mode 100644 artwork_prices.csv
 delete mode 100644 artwork_reviews.csv
 delete mode 100644 artwork_types.csv
 delete mode 100644 artworks.csv
 delete mode 100644 custom_artwork_images.csv
 delete mode 100644 data_test/data_01.py
 delete mode 100644 device_brands.csv
 delete mode 100644 device_colors.csv
 delete mode 100644 devices.csv
 delete mode 100644 input_data.py
 delete mode 100644 items.csv
 delete mode 100644 regular_artwork_images.csv
 delete mode 100644 test/haha.txt
 delete mode 100644 test/hoho.py
 delete mode 100644 test/number.py
 delete mode 100644 test/number.txt
 delete mode 100644 test/rlt.txt
 delete mode 100644 test/test.py
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) » git status
On branch Feature/Artwork-model-modify
nothing to commit, working tree clean
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) » git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(master○) » git pull origin master
From https://github.com/wecode-bootcamp-korea/casetify_backend
 * branch            master     -> FETCH_HEAD
Already up to date.
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(master○) » git rebase -i master Feature/Artwork-model-modify
[detached HEAD 6c4e8a5] modify artwork.models
 Date: Wed Jan 15 23:42:56 2020 +0900
 Committer: MarieJung <marie@MarieJungui-MacBookPro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 6 files changed, 84 insertions(+), 88 deletions(-)
 delete mode 100644 artwork/migrations/0002_auto_20200115_0344.py
 delete mode 100644 artwork/migrations/0003_auto_20200115_1549.py
 create mode 100644 order/migrations/0001_initial.py
Successfully rebased and updated refs/heads/Feature/Artwork-model-modify.
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) »
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) » tig
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) »
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) » git push origin Feature/Artwork-model-modify -f
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 12 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.63 KiB | 1.63 MiB/s, done.
Total 12 (delta 8), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8), completed with 6 local objects.
To https://github.com/wecode-bootcamp-korea/casetify_backend.git
 + aa0f122...6c4e8a5 Feature/Artwork-model-modify -> Feature/Artwork-model-modify (forced update)
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) »
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) »
(wehome_conda) marie@MarieJungui-MacBookPro:~/casetify(Feature/Artwork-model-modify○) »

rebase를 위한 스쿼시

tig확인화면

Reference

profile
#의식의흐름 #순간순간 #생각의스냅샷

0개의 댓글