본문 바로가기
CI&CD/Git

[Git] git rebase 후, git cherry-pick

by TSpoons 2024. 7. 25.

 

 

https://studyhoons.tistory.com/19

 

Github 사용 배경과 git 소개 - report

Git과 버전 관리 시스템 -  현대 소프트웨어 개발의 필수 도구소프트웨어 개발에서 버전 관리는 핵심적인 과정입니다. 과거에는 수동 백업과 릴리스 관리를 통해 이루어졌던 이 작업이, 오늘날

studyhoons.tistory.com

 

(위 사진을 참고하여 진행하면 좋다.)

 

맨날 merge만 하다가 rebase를 할 수 밖에 없는 상황에 마주쳤다.

git branch backup_branch

git rebase -i <config.h가_추가된_커밋의_부모_커밋_해시>

 

확인 --> 안됨

왜냐하면 변경을 안했기 때문이다. 

 

  /home/tspoon/workspace/ros-repo-5/.git/rebase-merge/git-rebase-todo           
pick a170b4d create : code : RH_control
pick e1072a4 delete : code : RFID_test/SPI_test
pick 6112e42 create : code : check_park with ROS2
pick c54849f update : code : ROS_check_test
pick 83a320c update : code : update code
pick 290c5b9 update : code : GUI update

# Rebase 02ef6a2..290c5b9 onto 02ef6a2 (6 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
#                    commit's log message, unless -C is used, in which case
#                    keep only this commit's message; -c is same as -C but
#                    opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
                               [ Read 34 lines ]

 

 

git rebase -i help

This file is the interactive rebase todo list opened by the git rebase -i command. It shows the commits that are part of the rebase operation and allows you to modify how they will be applied. Let's break down what we're seeing:


The rebase range is shown:
# Rebase 02ef6a2..290c5b9 onto 02ef6a2 (6 commands)
The file also includes a list of available commands and their descriptions:

p, pick: use commit as is
r, reword: use commit, but edit the commit message
e, edit: use commit, but stop for amending
s, squash: use commit, but meld into previous commit
f, fixup: like squash, but keep only the previous commit's message
x, exec: run a shell command
b, break: stop the rebase process temporarily



To proceed with the rebase, you would typically:

Edit this file to change the action for each commit as needed (e.g., changing "pick" to "squash" or "edit").
Save and close the file.
Git will then process each commit according to your instructions.

Would you like me to explain how to use any of these commands in more detail?


# Check the status of the rebase
git status

# If resolving conflicts, continue the rebase
git rebase --continue

# If you want to abort the rebase
git rebase --abort

# If you want to skip the current commit
git rebase --skip

# If you need to manually remove the rebase-merge directory and start fresh
rm -fr .git/rebase-merge
git rebase -i 02ef6a2f57d5d66317e702b8863f1217a58127f7

 

 

 

변경 완료 후 ctrl+x!

 

 

공용 repo에서 .gitignore 하기 전 tracking 하고 있는 파일 삭제

git rm --cached [캐시삭제할 파일]

 

 

git push --set-upstream origin backup_branch
or
git push -u origin backup_branch

 

 

엎친데 덥친 격.. 
PAT 토큰 기간도 만료되었다.

 

접근 권한이 없다..?

 

아 repo 접근에 check를 안했다.

 

다시 만들고

 

 

 

이제 dev에 merge할 때 충돌이 일어나지 않을지 테스트 해보자.

- backup-dev 브랜치 만들기

 

 

 

 

1. backup_branch에 backu_dev 그냥 merge

실패! 

2. backup_branch에 backup_dev의 commit cherry-pick

성공!

 

 (dev에 합쳐야 하는데.. 어지럽군)

git checkout backup-dev
git merge -s ours backup_branch
git push origin backup-dev

 

실패!

 

3.  되는 거로 여러 번 해야겠다!

git cherry-pick <start_commit>^..<end_commit>

 

한 번에 여러 커밋을 cherry-pick할 때 충돌이 해결되지 않은 상태에서 다음 커밋으로 진행할 수 없으니

일단 conflict 전까지 진행 

 

??

 

설마 공용 repo 캐시 문제인가?

 

딩동댕..!

 

복구 완료!!

 

 

여러분 ,gitignore는 꼭 파일 올리기 전에 진행하시고, 이미 올린 파일이면 꼭 지우고 다시 .gitignore 작성해주세요..!