Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a258e2

Browse files
committed
Add post on selectively adding files to git commit in VS Code
1 parent bc5ccb5 commit 8a258e2

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
10.6 KB
Loading
10.1 KB
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Title: VS Code Tip Of The Day - Selectively Adding Files To A Git Commit
2+
Date: 2021-04-03 10:26
3+
Modified: 2021-04-03 10:26
4+
Category: Posts
5+
tags: git,vscode
6+
cover: static/imgs/vscode.jpg
7+
summary: Recently I figured out a way to selectively add files to a Git commit.
8+
9+
Small tip: sometimes when working on something I find myself making changes to many
10+
files. I then only want to include a few of those files in my next Git commit. To
11+
date I've always just manually done a `git add <file>` in the terminal for each
12+
file I want to add, but this is tedious if there's many of them.
13+
14+
Turns out there's an easy way to do this in VS Code. If you go to the Source Control
15+
item on the left nav (the icon that looks like a branch), you’ll see a list of all
16+
untracked and modified files. For example:
17+
18+
![Showing Modified Files in the Source Control View]({static}/static/imgs/source-control-min.png)
19+
20+
In this screenshot you can see I have a number of files that have been modified (the
21+
ones with the "M" beside them) and two new (untracked) files (the ones with the "U"
22+
beside them).
23+
24+
If you want to see what's changed in any of the modified files, clicking the item will
25+
bring up a diff window. If you then want to include (or "stage") this file for the
26+
next commit, right-click it and pick "Stage Changes":
27+
28+
![Selecting Stage Changes]({static}/static/imgs/stagechanges-min.png)
29+
30+
Repeat for each file you want to include, and then do a `git commit` to complete the
31+
commit. Alternatively if you're anti-terminal you can click the checkmark on this
32+
same view to complete the commit.

0 commit comments

Comments
 (0)