create account

How to do a partial commit with VS Code by themarkymark

View this thread on: hive.blogpeakd.comecency.com
· @themarkymark ·
$24.90
How to do a partial commit with VS Code
![image.png](https://files.peakd.com/file/peakd-hive/themarkymark/YJxWPuQk-image.png)

VS Code has amazing git support.  One of the features I really love is the ability to commit partial file updates.

**Why would you want to do that?**

Say you are working on a project, you end up coding one thing but then start working on another feature without committing the previous changes.  Let's say you added a function, and only want to commit that function and ignore other changes.  VS Code has you covered!

Let's start with a simple piece of code.

https://i.imgur.com/BqQYMBg.png

This code is all committed, let's go ahead and make a few changes.

https://i.imgur.com/uDbyQOz.png

This is really simple and rather dumb code, but let's pretend it isn't.

I first created the get_webpage() function to wrap the requests call.  I later added the print_web_response() function just so we can have a second simple function.

I want to go ahead and commit just the changes that involve get_webpage() and then do a separate commit for the print_web_response() code.

First you want to "Open Changes"

https://i.imgur.com/NzpBqLW.png

https://i.imgur.com/QF57xZt.png

From there you have a really useful visual diff view of your code.   Select the lines you want to commit and right click and select **Stage Selected Ranges**

https://i.imgur.com/nOjp17D.png

You should see the diff update reflecting the changes to what is new.

https://i.imgur.com/3odcbqX.png

Let's do a **git status** to see what is staged.

https://i.imgur.com/NiMBwH2.png

Here you can see app.py is staged, but wait it is also unstaged?

The reason for this is because only a few lines are staged, a rather advanced but useful git feature.  Let's commit!

![image.png](https://files.peakd.com/file/peakd-hive/themarkymark/scvB12h5-image.png)

https://i.imgur.com/9cdyHQE.png

An updated git status shows there are still changes that need to be staged and commited.

This is a useful feature that VS Code makes super easy to work with.  Keep it in mind when you forget to stage some code without staging the entire file.

<sub>Cover Image [Source](https://launchdarkly.com/blog/launched-version-2-of-the-launchdarkly-visual-studio-code-extension/)</sub>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 465 others
👎  , , , , ,
properties (23)
authorthemarkymark
permlinkhow-to-do-a-partial-commit-with-vs-code
categorydevelopment
json_metadata{"app":"peakd/2020.10.5","format":"markdown","tags":["development","programming","vscode","palnet","neoxian","technology","archon","tutorial"],"links":["https://launchdarkly.com/blog/launched-version-2-of-the-launchdarkly-visual-studio-code-extension/"],"image":["https://files.peakd.com/file/peakd-hive/themarkymark/YJxWPuQk-image.png","https://i.imgur.com/BqQYMBg.png","https://i.imgur.com/uDbyQOz.png","https://i.imgur.com/NzpBqLW.png","https://i.imgur.com/QF57xZt.png","https://i.imgur.com/nOjp17D.png","https://i.imgur.com/3odcbqX.png","https://i.imgur.com/NiMBwH2.png","https://files.peakd.com/file/peakd-hive/themarkymark/scvB12h5-image.png","https://i.imgur.com/9cdyHQE.png"]}
created2020-10-21 05:46:06
last_update2020-10-21 05:46:06
depth0
children3
last_payout2020-10-28 05:46:06
cashout_time1969-12-31 23:59:59
total_payout_value14.512 HBD
curator_payout_value10.386 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,223
author_reputation1,774,102,101,992,747
root_title"How to do a partial commit with VS Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,189,346
net_rshares102,292,595,836,647
author_curate_reward""
vote details (535)
@amirl ·
That is cool indeed. I prefer webstorm though since I got used to from my intellij era.
How do you like the vs code debug?
properties (22)
authoramirl
permlinkqrc275
categorydevelopment
json_metadata{"app":"hiveblog/0.1"}
created2021-04-10 05:35:30
last_update2021-04-10 05:35:30
depth1
children0
last_payout2021-04-17 05:35:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length122
author_reputation-35,879,592,983,501
root_title"How to do a partial commit with VS Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id102,944,304
net_rshares0
@poshbot ·
https://twitter.com/itsjustmarky/status/1318876072042205184
properties (22)
authorposhbot
permlinkre-how-to-do-a-partial-commit-with-vs-code-20201021t112545z
categorydevelopment
json_metadata"{"app": "beem/0.24.8"}"
created2020-10-21 11:25:45
last_update2020-10-21 11:25:45
depth1
children0
last_payout2020-10-28 11:25:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length59
author_reputation5,554,335,374,496
root_title"How to do a partial commit with VS Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,192,345
net_rshares0
@poshbot ·
https://twitter.com/Bhattg18/status/1318876604555128833
properties (22)
authorposhbot
permlinkre-how-to-do-a-partial-commit-with-vs-code-20201021t113202z
categorydevelopment
json_metadata"{"app": "beem/0.24.8"}"
created2020-10-21 11:32:03
last_update2020-10-21 11:32:03
depth1
children0
last_payout2020-10-28 11:32:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length55
author_reputation5,554,335,374,496
root_title"How to do a partial commit with VS Code"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,192,392
net_rshares0