How do you commit only part of the changes in a file?
BeginnerConceptCommits, branches and tags
Answer
Use interactive patch staging. Git splits the diff into hunks and asks per hunk: y stage, n skip, s split, e edit manually.
git add -p path/to/file
git diff --staged
More on Commits, branches and tags
How do you write a good commit message?BeginnerWhat is the difference between `git add .`, `git add -A` and `git add -u`?BeginnerHow do you change the last commit message or add a forgotten file?BeginnerWhat is the difference between `git switch`, `git restore` and `git checkout`?BeginnerWhat is the difference between lightweight and annotated tags?BeginnerHow does `git describe` work and where is it useful?Intermediate