0

I run these command to commit:

git add --all -p
// Then use "y" to stage hunks, and use "n" to not stage hunks
// I want to commit hunks which staged with "y"

git commit -a
// Then commit all

But when I check, all of hunks which used "y" and "n" in git add committed to branch How could I just commit just hunks which I selected when using git add?

Matt
  • 12,848
  • 2
  • 31
  • 53
cmdntd
  • 11
  • 4
  • 2
    Don't run git commit with `-a`? You're telling git to stage everything modified and deleted and commit it. Also, you stage hunks, not hulks. – Hasturkun Jul 04 '21 at 12:31
  • 1
    Maybe this helps? https://stackoverflow.com/questions/1085162/commit-only-part-of-a-file-in-git – Mario Varchmin Jul 04 '21 at 12:34

1 Answers1

2

Simply use git commit instead of git commit -a. The -a option will stage all new and modified files, basically making your previous staging activity obsolete.

Look here: https://git-scm.com/docs/git-commit And here: https://git-scm.com/book/en/v2/Git-Tools-Interactive-Staging

Mario Varchmin
  • 3,704
  • 4
  • 18
  • 33