O-RAN SC에 오픈소스 기여를 해보자 5일차 - Rebase 하기

0

opensource

목록 보기
5/6

O-RAN AIMLFW modelmgmtservice에 code review를 받은 지 어언 한달... 아직도 나는 code approve를 받지 못했다. ㅜㅜ
https://gerrit.o-ran-sc.org/r/c/aiml-fw/awmf/modelmgmtservice/+/13286


그러던 중 10월 초에 드디어 approval되었는데 문제는 code merge에 실패했다.


merge를 해보도록 하자.

현재의 commit 상황은 다음과 같다.

[master branch]
A - B - D - E - F (HEAD)
    \
      C (내 commit)

같은 master branch에서 서로 다른 commit으로 갈린 경우이다. O-RAN gerrit은 개발할 때 branch를 따로 떼어내서 합쳐도 되는 지 아직 잘 모르겠어서 master로만 하고 있었는데, 보기 좋게 merge conflict가 발생한 것이다. 다음에는 branch를 나누어서 개발해보고 feat별로 master에 병합해보도록 해야겠다.

일반적으로 merge방법은 두 가지가 있다. 하나는 git merge이고, 다른 하나는 git rebase이다. 이들의 차이를 쉽게 정리하면 다음과 같다.

  • merge
[master branch]
A - B - D - E - F - G (HEAD)
    \			  /
      C (내 commit) 

내 commit인 C와 HEAD였던 F commit을 서로 병합하여 충돌을 하나하나 해결한 다음에, merge했다는 G commit을 만들어낸다.

이렇게 merge를 사용하면 내가 B commit에서 빠져나와서 C를 만들어냈다는 것을 쉽게 알 수 있다. 즉, commit의 history가 남아있다는 것이다.

그렇다면 rebase는 이전 commit history를 안남는다는 것인가?? 정확히는 commit기록을 하나로 연결한다. 따라서 이전의 commit history를 알기 힘들 수 있다.

  • rebase
[master branch]
A - B - D - E - F - C (HEAD)

내 commit인 C를 F와 병합한 다음 F앞에 두는 것이다. 이때 별도의 병합 commit이 없다는 것이 장점이다. 정말 base를 다시 재조정한 것이다. 그런데 rebase를 사용하면 commit의 history가 모호해지는 단점이있다. 즉, 내 commit인 C가 B에서 유래된지를 모르는 것이다.

그래서 정리하자면 merge는 merge commit이 만들어지지만 commit의 history를 유지하고 싶다면 사용하는 것이고, rebase는 merge commit은 없지만 commit의 history를 유지하지 않고, 깔끔하게 메인 branch에 반영되고 싶을 때 사용한다.

그럼 내 경우는 어떤 것을 써야할까?? 나의 경우는 git rebase를 써야한다. 왜냐하면 gerrit은 commit단위로 code review를 받는다. github처럼 branch마다의 pull request가 따로 있는 것이 아니라는 것이다. 따라서, 내 commit이 이미 code review page를 만들어놨는데, 새로운 git merge로 새로운 병합 commit을 만든다?? 그럼 새로운 code review page가 만들어지고, 내 이전 code review page의 이력은 무용 지물이 된다.

정리하자면 O-RAN gerrit의 경우 내 code review page가 있다면 git rebase를 사용하고, 없다면 git merge를 사용해도 된다. 어차피 code review page가 없어서 새로운 commit이 만들어져도 상관이 없기 때문이다.

git rebase

git rebase origin master

이렇게하면 vscode에서 알아서 code merge를 해주고, 충돌이 난 부분들은 직접 해결하라고 알려줄 것이다.
다음으로 rebase 진행을 계속시켜주어 완료시켜주자

git rebase --continue

You must edit all merge conflicts and then
mark them as resolved using git add

git rebase --continue 실행 시에 위와 같이 나온다면, conflict 중에 수정된 파일을 git add을 사용해 staging area로 올려야 한다는 것을 알려주는 것이다.

git status

interactive rebase in progress; onto 4fca931
Last command done (1 command done):
   pick 1ea69fd Implement the configuration data management code in modelmgmtservice
No commands remaining.
You are currently rebasing branch 'master' on '4fca931'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   config/config_manager.go
        new file:   config/config_manager_test.go
        new file:   config/data.go
        new file:   config/env_loader.go
        new file:   config/env_loader_test.go
        new file:   config/validator.go
        new file:   config/validator_test.go
        modified:   go.mod
        modified:   go.sum
        modified:   main.go

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   go.mod
        modified:   go.sum

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        apis_test/testing.log
        build_image.sh
        config/testing.log
        temp.json

필자의 경우 go.mod, go.sum이 그 대상인 것이었다.

git add ./go.mod
git add ./go.sum 

수정된 사항을 staging area로 올려둔 뒤에 다시 git rebase --continue로 rebase를 마저 완료한다.

it rebase --continue 
[detached HEAD e63a2ba] Implement the configuration data management code in modelmgmtservice
 10 files changed, 560 insertions(+), 39 deletions(-)
 create mode 100644 config/config_manager.go
 create mode 100644 config/config_manager_test.go
 create mode 100644 config/data.go
 create mode 100644 config/env_loader.go
 create mode 100644 config/env_loader_test.go
 create mode 100644 config/validator.go
 create mode 100644 config/validator_test.go
Successfully rebased and updated refs/heads/master.

이렇게 나오면 성공이다.

다음으로 git log를 통해 rebase가 잘 완료되었는 지 확인하도록 하자. 이는 내가 만든 commit이 master branch의 HEAD에 있고, 이전 HEAD commit이 뒤에 있어야 한다.

git log

commit b420b8a621593e2404e56ab1d59796653d110f2c (HEAD -> master)
Author: gyuyoung <gyoue200125@gmail.com>
Date:   Thu Aug 29 23:30:58 2024 +0900

    Implement the configuration data management code in modelmgmtservice
    
    - Add 'config' package for easy and safe handling of configuration data
    - Add 'godotenv' library to load environment files(ex, .env)
    - Update 'main.go' to utilize the new 'config' package
    - Modify env_loader.go to use viper package
    - Add new validation layer to check whether config data is valid or not
    - Add test codes of config package
    
    Issue-ID: AIMLFW-147
    
    Change-Id: I3cea95f0d528c27ccf82a802759b965b06afe34d
    Signed-off-by: gyuyoung <gyoue200125@gmail.com>

commit 4fca931bae46ef9221e2005d9ad6d12b19767e35 (origin/master, origin/HEAD, gerrit/master)
Author: rajdeep11 <rajdeep.sin@samsung.com>
Date:   Wed Oct 9 17:33:42 2024 +0530
...

성공이다!! 참고로 여기서 보이는 Change-Id가 하나의 code review id이다. 따라서 merge로 병합하게되면 이 값이 바뀌게 되어 code review page가 달라질 것이다.

이제 rebase를 완료했다는 commit msg를 추가하도록 하고, git review로 code review를 만들어주면 된다.

git commit --amend

commit을 추가해주도록 하자.

이 후에 code review를 다시 올리도록 하자.

git review 
remote: 
remote: Processing changes: refs: 1, updated: 1        
remote: Processing changes: refs: 1, updated: 1        
remote: Processing changes: refs: 1, updated: 1, done            
remote: commit b420b8a: warning: subject >50 characters; use shorter first paragraph        
remote: 
remote: SUCCESS        
remote: 
remote:   https://gerrit.o-ran-sc.org/r/c/aiml-fw/awmf/modelmgmtservice/+/13286 Implement the configuration data management code in modelmgmtservice        
remote: 
remote: The following approvals got outdated and were removed:        
remote: * Verified+1 by ORAN Jobbuilder        
remote: * Verified+1 by ORAN Required GHA        
remote: 
remote: 
To ssh://gerrit.o-ran-sc.org:29418/aiml-fw/awmf/modelmgmtservice
 * [new reference]   HEAD -> refs/for/master

이제 확인해보면 rebase 후의 commit msg, 새로운 patchset도 잘 반영되어 있을 것이다.

잘 반영된 것을 볼 수 있다. 여기서 마무리하지 않고, 내가 rebase했다는 사실을 REPLY를 통해서 답장하도록 하자.


approval해주겠지?!

Opensource는 참 재밌다. 요즘 회사에서 윗선들의 정치싸움을 보고있자니 일하고싶은 의욕이 정말 싹 사라지고 있다. 개발에만 집중하고 싶은데 윗선들은, 사내 자리싸움으로 내 등까지 터지게 만들고 있어서 정말 지친다. 어쩌면 순수하게 개발에만 집중할 수 있는 시간은 opensource에 참여하고 있는 지금 이 시간이 아닐까 싶다.

후... 나도 더 나이가 들게되면, 내가 싫어하는 윗선들처럼 혀만 굴리는 사람이 될까 너무 무섭다...

0개의 댓글