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

前端 未结 5 1346
醉话见心
醉话见心 2020-12-22 19:53

VSCode has excellent git integration but I can\'t find a way to do partial commits. Basically, I want to be able to select specific changes in my files and stage them withou

相关标签:
5条回答
  • 2020-12-22 20:01

    ⚡ 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.

    Peace! ✌️

    0 讨论(0)
  • 2020-12-22 20:05

    Update: October 2017: In the latest VSCode as of October 2017 (version 1.18) you can actually stage specific lines really easy just like you would do it with the git CLI git add -p. You just have to click on the edited line from the side like, watch the diff and apply it or not.

    0 讨论(0)
  • 2020-12-22 20:12

    Use Interactive staging.

    command - git add -p <file_name> this will show you the file, and you can choose which one you want to commit after parting the changes

    0 讨论(0)
  • 2020-12-22 20:18
    • 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.

    0 讨论(0)
  • 2020-12-22 20:23

    This option has been moved to the palette:

    shift+command+P and type "stage selected ranges"

    0 讨论(0)
提交回复
热议问题