git add -p ( git add patch )

부가 설명
깃 커밋 클린하게 작성하기 ( 한 파일 변경 내에서도 나눠서 커밋하기 )
Tags
commit
 
 

커맨드로 작업

$ git add -p
변경 사항이 그룹별로 묶여서 차례차례 Stage 할 건지 물어본다.
하나의 그룹을 hunk 라고 부른다.
아래 커맨드를 이용해서 적절히 hunk를 반영할 건지 건너뛸 건지 선택하면 된다.
자동으로 구분된 hunk 단위가 마음에 안든다면 s를 눌러서 더 잘게 쪼갤 수 있고, 이것도 마음에 안든다면 e를 통해 manual로 hunk를 편집할 수도 있다.
y - stage this hunk n - do not stage this hunk q - quit; do not stage this hunk or any of the remaining ones a - stage this hunk and all later hunks in the file d - do not stage this hunk or any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk k - leave this hunk undecided, see previous undecided hunk K - leave this hunk undecided, see previous hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
 

VSCode로 GUI로 작업

Compare 모드로 진입한 상태에서, 이번에 Stage로 올리고 싶은 부분만 선택한 후, VSCode 우측 상단 … 버튼을 눌러 Stage Selected Ranges를 클릭해 선택한 영역만 스테이지로 올릴 수 있다.
단축키 : 커맨드+K 이후 옵션+커맨드+S
notion image
 
notion image