How can I commit some changes to a file, but not others, in VSCode?

Solution 1:

  • Open up the Source Control view, then click a changed file to open the comparison.

  • Select the lines you want to stage.

  • Click '...' then Stage Selected Ranges.

enter image description here

Solution 2:

⚡ Summing up everything in this post with a gif.

  1. Make sure you're in the source control view to use this feature
  2. Select the range of code
  3. Open ··· at the top-right corner of the editor (not the ··· at the top of the git panel on the left)
  4. You can also press COMMAND (⌘) + K + COMMAND (⌘) + S to open keyboard shortcuts and search for range and then set a keyboard shortcut for this action.

VSCode Range Select Commit

Peace! ✌️