공부/Linux

IDE로 코드 리뷰할때 개인적인 팁

토고미 2024. 4. 18. 21:19

일단 git 웹 뷰로는 솔직히 코드 리뷰 하기가 힘들다. 딱 바뀐 부분만 나오기 때문이다.

 

그래서 git clone 하여 개인 IDE로 열어서 해당 브랜치로 checkout 하여 보는데

막상 그렇게하면 어디가 바뀌었는지 알기가 쉽지 않다.

 

vscode에서는 unstage 상태의 변경사항(add가 되지 않은 변경사항)은 표시해준다.

그러면 commit된 것들을 unstage로 되돌리면 된다.

 

먼저 git log 명령어로 어디까지 되롤릴지 확인한다

> git log

commit a9d21cb2bebc66cdb811693ae61f8dd0b45703cf (HEAD -> https)
Author: Seungwon Lee <seungwon_lee@tmax.co.kr>
Date:   Tue Jul 26 16:41:51 2022 +0900

    Add TLS option for webhook

commit 6cd81155bae12b44a253b8adbccc1b1576a26ca8 (origin/master, origin/HEAD, master)
Merge: ffc4d2cd 1847e6e5
Author: arik <alon.arik@gmail.com>
Date:   Mon Jul 4 15:46:48 2022 +0300

    Merge pull request #6 from robusta-dev/cluster_role_api_family

    Change ClusterRole api family from rbac/v1beta1 to rbac/v1

commit 1847e6e59d0b8ea0bf1c747deb2a90c74448f766 (origin/cluster_role_api_family)
Author: Robusta Runner <runner@robusta.dev>
Date:   Mon Jul 4 15:45:07 2022 +0300

    Change ClusterRole api family from rbac/v1beta1 to rbac/v1

commit ffc4d2cdd9258ce36137a7b2192dac0f35b2a555
Author: Natan Yellin <aantn@users.noreply.github.com>
Date:   Fri Apr 8 13:30:09 2022 +0300

    Update README.md

 

예를 들어서 현재 리뷰해야할 커밋이 상위 두 개라면,

그러니까 commit hash 값이 a9d21c, 6cd811 인 두 개의 커밋을 리뷰해야한다면

아래와 같이 git reset 명령어로 두 개의 커밋을 unstage 상태로 되돌린다

> git reset HEAD~2
Unstaged changes after reset:
M       cmd/webhook.go
M       config/config.go
M       config/sample.go
M       examples/conf/kubewatch.conf.webhook.yaml
M       pkg/controller/controller.go
M       pkg/handlers/webhook/webhook.go

 

그러면 아래와 같이 변경된 사항이 표시된다.

 

 

다시 원래대로 돌아가려면 git reflog와 git reset 명령어를 이용한다.

> git reflog
ffc4d2cd (HEAD -> https) HEAD@{0}: checkout: moving from https to https
ffc4d2cd (HEAD -> https) HEAD@{1}: reset: moving to HEAD~2
a9d21cb2 HEAD@{2}: checkout: moving from master to https
6cd81155 (origin/master, origin/HEAD, master) HEAD@{3}: checkout: moving from 6cd81155bae12b44a253b8adbccc1b1576a26ca8 to master
1847e6e5 (origin/cluster_role_api_family) HEAD@{5}: checkout: moving from master to 1847e6e

> git reset --hard a9d21cb2
HEAD is now at a9d21cb2 Add TLS option for webhook

아까 위에서 git log의 결과로 첫 commit이 a9d21cb2 였으므로 해당 커밋으로 돌아간다.

 

'공부 > Linux' 카테고리의 다른 글

Linux cpu, memory, storage 정보 확인  (0) 2022.08.12
Bash를 이용해 여러 파일의 내용을 치환하기  (0) 2022.07.15