Managing and distinguishing between changed files and untracked files in Visual Studio Code (VSCode) is a common requirement, especially when using Git for version control. Here are detailed steps and methods to help you effectively distinguish these two categories.
1. Using VSCode's Source Control Panel
VSCode integrates robust source control tools, typically via Git. You can view changed and untracked files by following these steps:
-
Open the Source Control Panel:
- Locate the branch icon in the sidebar, which serves as the indicator for the Source Control panel. Click it or use the shortcut
Ctrl+Shift+G(Mac:Cmd+Shift+G).
- Locate the branch icon in the sidebar, which serves as the indicator for the Source Control panel. Click it or use the shortcut
-
View the Change List:
- In the Source Control panel, you'll see a list divided into sections, including Changes (for changed files) and Untracked (for untracked files), which are clearly separated.
-
Manage File States:
- For untracked files, right-click the file and select Stage Changes to track it or Discard Changes to ignore it.
- For changed files, right-click to choose to commit or discard changes.
2. Using Git Command-Line Tools
If you prefer using the command line, VSCode's integrated terminal provides excellent support. You can run Git commands directly in the integrated terminal to manage file states:
-
Open the Terminal:
- Use the shortcut
Ctrl+(Mac:Cmd+) or access Terminal from the View menu.
- Use the shortcut
-
View Untracked and Changed Files:
- Run
git statusto list all untracked files and modified files. Untracked files appear under 'Untracked files', while modified files are listed under 'Changes not staged for commit'.
- Run
-
Handle These Files Separately:
- Use
git add <filename>to stage untracked files. - Use
git checkout -- <filename>to discard changes to modified files.
- Use
Practical Example
Suppose I modified index.html and added a new file style.css in a project, but did not track the new file.
- In the Source Control panel,
index.htmlappears under Changes, whilestyle.cssappears under Untracked. - Using
git statusin the terminal, I seeindex.htmllisted under 'Changes not staged for commit', whilestyle.cssappears under 'Untracked files'.
These tools and methods help me maintain the organization of the codebase and effectively handle different file states.