コードの一部だけコミットする(git add -p)
#Git #GitHub
修正したコードの中で一部だけコミットしたい場合は git add -p を使うと、一部分だけ選んでコミットできる
code:bash
$ git add -p .
diff --git a/app/views/top/index.html.slim b/app/views/top/index.html.slim
index 4db9d0d..a5fb539 100644
--- a/app/views/top/index.html.slim
+++ b/app/views/top/index.html.slim
@@ -8,7 +8,7 @@
br
| 利用規約・プライバシーポリシーに
br
- | 同意するものとします。
+ | 同意するものとしますYO
.relative
.custom-shape-divider-top
svg[data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none"]
(1/2) Stage this hunk y,n,q,a,d,j,J,g,/,e,??
変更を加えた固まりごとにstageにあげるか聞かれる。( Stage this hunk y,n,q,a,d,j,J,g,/,e,?? )
stageにあげたい場合は、y
stageにあげない場合は、n
手動で内容を変更したい場合は、e
それ以外にもいろいろある(以下、公式ドキュメントより)
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
https://git-scm.com/docs/git-add
コミットしたい部分を選ぶと選んだ箇所だけstageに上がり、それ以外はnot stageになる(以下のような感じ)
code:bash
$ git st
On branch test
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: app/views/top/index.html.slim
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: app/views/top/index.html.slim