본문 바로가기
Git

git 커밋 git add -p 명령어를 사용해서 커밋하기

by @hohoya33 2021년 10월 11일

수정된 파일을 커밋하기 전 변경된 파일들을 확인하고 스테이지에 올리기 위해서는 git add라는 명령어를 사용하게 됩니다.

git add 대신 git add -p라는 명령어도 사용 할 수 있습니다.

 

git add -p

 

git add -p 를 사용하게 되면, 현재 변경된 코드들의 파일들을 하나씩 보여주고, 해당 파일을 스테이지에 올릴 것인지, 올리지 않을 것인지 바로 선택 할 수 있습니다. 한마디로 위에서 설명한 git status / git diff / git add (혹은 git checkout -- 파일명) 을 한번에 진행 하는 것입니다.

 

 만약 특정 파일만 스테이지에 올리고 싶다면 하나씩 변경 사항을 확인하고 스테이지에 올리는 과정을 진행 해야 하지만, git add -p 명령어를 입력하면 각 파일의 변경사항을 바로 확인 하고 스테이지에 올릴지 결정 할 수 있습니다.

 

 

Stage this hunk [y,n,q,a,d,s,e,?]?  라는 명령어가 있는데 기본적인 것은 y,n,q만 알고 있어도 가능합니다.

(hunk는 스테이지에 올라 갈 수 있는 하나의 단위를 말합니다.)

 

 

y는 해당 hunk를 스테이지에 올리고,

n은 해당 hunk를 스테이지에 올리지 않고,

q는 종료

 

 

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

개의 댓글