|
| 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 | + |
| 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 | + |
| 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