[Git] '특정 파일'의 '특정 라인'만 커밋

qwe8851·2023년 12월 15일
0

✏️ git

목록 보기
9/14

git add -p {파일명}
해당 명령어를 사용하게되면 자동으로 변경된 코드라인을 hunk 단위로 보여주고, 해당 hunk에 대해 Stage, Skip 등의 action을 취할 수 있다. (hunk는 Stage될 수 있는 파일 조각 단위)

또한, 이 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

자주 사용되는 명령어는 y, n, q, s, e이다.

y : 이 hunk를 stage 시킨다.
n : 이 hunk를 stage하지 않는다.
q : add 과정을 종료한다.
s : 이 hunk를 더 작은 단위의 hunk로 나눈다. 한 hunk에 대해서 1번만 실행할 수 있다.
e : 현재 hunk 내용을 직접 편집한다.

refe: https://github.com/z1zon/z1zon-WIL/issues/3

profile
FrontEnd Developer with React, TypeScript

0개의 댓글