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

Skip to content

Add post on selectively adding files to git commit in VS Code #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added content/static/imgs/source-control-min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/static/imgs/stagechanges-min.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions content/vsctotd-selectively-adding-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Title: VS Code Tip Of The Day - Selectively Adding Files To A Git Commit
Date: 2021-04-03 10:26
Modified: 2021-04-03 10:26
Category: Posts
tags: git,vscode
cover: static/imgs/vscode.jpg
summary: Recently I figured out a way to selectively add files to a Git commit.

Small tip: sometimes when working on something I find myself making changes to many
files. I then only want to include a few of those files in my next Git commit. To
date I've always just manually done a `git add <file>` in the terminal for each
file I want to add, but this is tedious if there's many of them.

Turns out there's an easy way to do this in VS Code. If you go to the Source Control
item on the left nav (the icon that looks like a branch), you’ll see a list of all
untracked and modified files. For example:

![Showing Modified Files in the Source Control View]({static}/static/imgs/source-control-min.png)

In this screenshot you can see I have a number of files that have been modified (the
ones with the "M" beside them) and two new (untracked) files (the ones with the "U"
beside them).

If you want to see what's changed in any of the modified files, clicking the item will
bring up a diff window. If you then want to include (or "stage") this file for the
next commit, right-click it and pick "Stage Changes":

![Selecting Stage Changes]({static}/static/imgs/stagechanges-min.png)

Repeat for each file you want to include, and then do a `git commit` to complete the
commit. Alternatively if you're anti-terminal you can click the checkmark on this
same view to complete the commit.