DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

d.yoshimitsu
d.yoshimitsu

Posted on

git add -pใฎใ™ใ‚ใ‚

ใ†ใฃใ‹ใ‚Š็ง˜ๅŒฟๆƒ…ๅ ฑใ‚’ใƒ—ใƒƒใ‚ทใƒฅใ—ใŸ็ตŒ้จ“ใฏใ‚ใ‚Šใพใ›ใ‚“ใ‹๏ผŸ
ใใ‚“ใชๆ‚ฒๅŠ‡ใ‚’ๅ›ž้ฟใ™ใ‚‹ใŸใ‚ใฎtipsใงใ™ใ€‚

ใใ‚‚ใใ‚‚

$ git add -A ใ™ใ‚‹ใชใ€‚
force pushไธฆใฎๅคง็ฝชใ‚„ใžใ€‚ๆ‚”ใ„ๆ”นใ‚ใ‚ใ€‚

git add -pใจใฏ

Git - git-add Documentationใ‹ใ‚‰ใฎๅผ•็”จ

-p
--patch
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See โ€œInteractive modeโ€ for details.

่ฆใ™ใ‚‹ใซaddใ™ใ‚‹ๅ‰ใซๅทฎๅˆ†ใ‚’ๅฏพ่ฉฑ็š„ใซ็ขบ่ชใงใใ‚‹ใ‚ณใƒžใƒณใƒ‰ใงใ™ใ€‚

Let's try

ใƒฏใƒผใ‚ญใƒณใ‚ฐใƒ„ใƒชใƒผใซๅทฎๅˆ†ใŒใ‚ใ‚‹็Šถๆ…‹ใงใ€ $ git add -p ใ—ใฆใฟใฆใใ ใ•ใ„ใ€‚

Screen Shot 2018-12-07 at 23.32.29.png

ใ“ใ‚“ใชๆ„Ÿใ˜ใซใชใ‚‹ใฏใšใงใ™ใ€‚
ๅทฎๅˆ†ใฎๅกŠ(hunk)ใ‚’ใ‚นใƒ†ใƒผใ‚ธใ™ใ‚‹ใ‹ใ‚’ๅฏพ่ฉฑ็š„ใซ่žใ‹ใ‚Œใ‚‹ใฎใงใ€[y,n,q,a,d,e,?]ใ‚’ไฝฟใฃใฆใ€ๅ‡ฆ็†ใ—ใฆใ„ใใพใ™ใ€‚

Stage this hunk [y,n,q,a,d,e,?]? 

ๅ›ฐใฃใŸใจใใฏ?ใ‚’ๅฎŸ่กŒใ—ใฆใใ ใ•ใ„ใ€‚helpใŒ่กจ็คบใ•ใ‚Œใพใ™ใ€‚

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
e - manually edit the current hunk
? - print help

ใชใ‚“ใ ใ‹่‰ฒใ€…ใ‚ใฃใฆไธๅฎ‰ใซใชใ‚‹ใ‹ใ‚‚ใ—ใ‚Œใพใ›ใ‚“ใŒใ€yใจnใฎ2ใคใ‚’่ฆšใˆใ‚Œใฐๅคงไธˆๅคซใงใ™ใ€‚

  • y
    ๅทฎๅˆ†ใฎๅกŠ(hunk)ใ‚’ใ‚นใƒ†ใƒผใ‚ธใƒณใ‚ฐใ—ใพใ™ใ€‚
    ๅทฎๅˆ†ใฎๅ†…ๅฎนใ‚’็ขบ่ชใ—ๅ•้กŒใชใ‘ใ‚Œใฐyใงใ™ใ€‚

  • n
    ๅทฎๅˆ†ใฎๅกŠ(hunk)ใ‚’ใ‚นใƒ†ใƒผใ‚ธใƒณใ‚ฐใ—ใพใ›ใ‚“ใ€‚
    ๅทฎๅˆ†ใฎๅ†…ๅฎนใ‚’็ขบ่ชใ—ๆ„ๅ›ณใ—ใชใ„็ง˜ๅŒฟๆƒ…ๅ ฑใ‚„ใ€ใƒ‡ใƒใƒƒใ‚ฐใƒญใ‚ฐๅ‡บๅŠ›็ญ‰ใŒๅซใพใ‚Œใฆใ„ใŸๅ ดๅˆใฏnใงใ™ใ€‚

ไธ€ใคๅ‡ฆ็†ใ™ใ‚‹ใจใพใŸๆฌกใฎๅทฎๅˆ†ใŒ่‡ชๅ‹•็š„ใซ่กจ็คบใ•ใ‚Œใ€ๅ…จใฆใฎๅทฎๅˆ†ใซๅฏพใ—ใฆๅ‡ฆ็†ใ™ใ‚‹ใพใง็ถšใใพใ™ใ€‚
โ€ป q ใงๅผทๅˆถ็š„ใซใใ‚Œไปฅ้™ใ‚’ๅ…จใฆใ‚นใƒ†ใƒผใ‚ธใƒณใ‚ฐใ›ใšใซadd -pใ‚’็ต‚ไบ†ใ™ใ‚‹ใ“ใจใ‚‚ๅ‡บๆฅใพใ™ใ€‚

ไธŠ่จ˜ใฎๅ‡ฆ็†ใ‚’็นฐใ‚Š่ฟ”ใ—ใฆใ‚นใƒ†ใƒผใ‚ธใƒณใ‚ฐใŒๅฎŒไบ†ใ—ใŸใ‚‰ใ€ใ„ใคใ‚‚ใฎใ‚ˆใ†ใซcommitใ‚’่กŒใฃใฆใใ ใ•ใ„ใ€‚

Screen Shot 2018-12-07 at 23.37.51.png

ๅ็œ

force pushไธฆใฎๅคง็ฝชใ‚„ใžใ€‚ๆ‚”ใ„ๆ”นใ‚ใ‚ใ€‚

ใจใ‹ใ„ใ„ใชใŒใ‚‰ใ€ใ‚ตใƒณใƒ—ใƒซใƒ—ใƒญใ‚ธใ‚งใ‚ฏใƒˆไฝœใ‚‹ใจใใซ-Aใ‚’ไฝฟใฃใฆใ—ใพใ„ใพใ—ใŸใ€‚ๆ‚”ใ„ๆ”นใ‚ใพใ™ใ€‚

Top comments (0)

Classic DEV Post:

Understanding git through images