How do I fix my source control tab on VS Code? - visual-studio-code

Every time I open a new folder from my files, Source Control thinks it's a repository. For example:
https://i.stack.imgur.com/fs4Ir.png
These are all files I've created in VS Code, but it considers them "untracked"

If VS Code shows the source control tab, it's because it found a .git folder either in the folder you opened or any of the ancestor. It will looks for such folder recursively, up to the root.
This folder contains all the local git database stuff.
You should look inside your folder structure up to find such folder and remove it (it's probably an hidden folder, you should set your options accordingly).
Another way to find where's this folder is located is to open a command prompt, cd your folder and run git rev-parse --show-toplevel. This will output the repo root folder.

Related

Why is Github desktop creating a new folder rather than using the one I specified when creating a new local repo?

I am looking to do something I thought was pretty simple... I have an existing folder (with project files) on my desktop that I would like have tracked by Github desktop for purposes of source/version control. It seems straightforward... I go to github desktop, select that I'd like to create a new repository, and point it at the folder on the desktop. Here is what I expect to happen:
Desktop
Project folder
Project files
(hidden) .git folder
(hidden) .gitattributes
Instead, this is what I get:
Desktop
Project folder
Project files
New folder with specified git repo name
(hidden) .git folder
(hidden) .gitattributes
I am not sure why this is happening and it is very frustrating. It looks to me like I have only two options here:
Cut and paste Project files into New folder with specified git repo name
Cut and paste .git folder and .gitattributes out of New folder with specified git repo name and into Project folder, delete New folder with specified git repo name, remove the new repo in Github Desktop when it says it can't find it, and "Add Existing repo" in Github Desktop and point it at Project folder.
Both of these approaches sort of feel like hacks and I am not sure what consequences, if any, may negatively impact my version control intention as a result. Is this a common problem? What should I do?
I wouldn't use github desktop to make your repository. If you don't have it already try installing git bash, a command line interface, and initialize git from there.
Find your existing folder and move to it using cd <folder name here> if you go into the wrong place use cd .. to move out/back one folder
When in your folder use git init to initialize git(the version control software)
Open GitHub Desktop once again and hit "add" then "add existing repository" finally "choose" and find your file in your file explorer
When you go to "Create a new repository":
Name: New folder with specified git repo name
Local Path: Desktop (ie one level up from Project files)
This will create the .git and .gitattributes in your existing folder without affecting the other files.
The Create a new repository dialogue seems to assume the name should be used as a new folder under the path you specify.
Note that if there are spaces in your name, it tries to replace them with hyphens.

VS Code: Use the list of multi-root workspace folders during dev container build

I have a ~/projects/ directory with a bunch of cloned Git repos in it. I like to select subsets of these and save them as VS Code multi-root workspaces as ~/projects/*.code-workspace.
I also use a dev container, configured with ~/projects/.devcontainer.json so that all the workspaces find it automatically.
When I build a dev container, I would love to be able to run some initialization logic with the input being the list of folders in the open workspace.
I can use ${containerWorkspaceFolder} in .devcontainer.json, but this gives me ~/projects, not the exact .code-workspace file, and there are multiple .code-workspace files in the directory. If I could get the path of the current .code-workspace file, I could parse the json and get the folder list, but it seems I can only get the parent folder.
I tried setting terminal.integrated.env.linux in foo.code-workspace to set a per-workspace environment variable CODE_WORKSPACE_FILE=~/projects/foo.code-workspace, but it isn't visible to the devcontainer build, only in integrated terminals I open after the workspace is already open in the container.
I see that there is a workspace.workspaceFolders() method in the vscode extension API. I don't want to write an extension just to expose that value to the devcontainers system, but maybe that's the only way currently.
Any other ideas?
It isn't exactly what you asked for, but you can use code-workspace files in a devcontainer if you mount your source code in devcontainer.json. You can use the mounts property in devcontainer.json (https://containers.dev/implementors/json_reference/).
First, add the following to your devcontainer.json file:
"mounts": [
{"source":"~/projects","/projects","type":"bind"},
],
Second move your .devcontainer folder to an empty directory. For example, you could make a folder named for the container template or your project in home directory, something like ~/nodejs-postgres. Copy your *.code-workspace files into the .devcontainer folder. You should have the following folder structure:
- ~/nodejs-postgres
- .devcontainer
- devcontainer.json
- project1.code-workspace
- project2.code-workspace
- ...
Next, edit the code-workspace files so the paths use /projects instead of ~/projects.
Finally open ~/nodejs-postgres in a devcontainer. After the container is built and ready to use, you should have a code window with just the devcontainer folder open. Your entire projects folder is mounted in the container, but the folders aren't open in vscode.
At this point, you can use the Add Folder to Workspace command to add a folder to the current workspace in the devcontainer or you can open one of your code-workspace files in an editor and click the Open Workspace button that comes up. After clicking the button, it will open the mounted project folders in the container.

Visual Studio Code source control full of 'changes' I was not aware of

How do I get rid of these 'changes' on Visual Studio Code? There are over thousands of files and I was not aware of these changes since I installed vs code on my MacBook. I tried git reset --hard on the terminal, but nothing has happened. I also do not recall having these files on my laptop and VS Code cannot even open these files. VS Code also failed to notify me of these 'changes'. Whenever I try to delete all the files, it says git: fatal: you are on a branch yet to be born
See screenshot below:
All of these "changes" are most likely do to you initializing git in a folder with lots of settings and configuration folders. For example, in the screenshot, I can see that most of the "changes" are from .eclipse folder, a folder Eclipse uses to store configurations. You usually cannot see these folders, because they are "hidden" folders.
Solution 1
The first solution is to add a .gitignore file, to ignore all of those unnecessary folders. To do this, just add a file named .gitignore to the current folder. Then in that file, put a list of all of the folders to be ignored. For example(Go through the list of "changes" and add more folders):
/.eclipse
Solution 2
The other solution to seeing these changes is just deleting the .git folder. You can't see this folder by default, because it is a hidden folder. To see this, you have to go to Finder, and press Command + Shift + .. After you see the .git folder, you can just delete it. The changes should now go away.

how to Move files upward in folder in github

I have the folder called, SpartanDrive-hansol, as you see in the picture, and it contains all the necessary files that I need. But just the folder, SpartanDrive-hansol, is unnecessary, and it causes a problem when I try to merge it with master branch because master branch does not have that folder.
Can anyone help me how to delete the unnecessary hierarchy of the folder? (But I need all the files that are in the folder) Thank you!
You can do it easily with the terminal. In the parent directory of the SpartanDrive-hansol folder, run the following command in the terminal:
mv SpartanDrive-hansol/* .
This will move all contents of the folder to your current folder, which in this case is the parent folder.

.gitignore not ignoring a folder within a directory

It seems a straightforward one, but having researched multiple ways to do it, I can't gitignore a folder within a directory.
I have a root directory which contains all of my code in it. Because it has some back-end NodeJS stuff in it, it has a 'node_modules' folder which contains hundreds of files. As a result, when I try to upload the entire parent folder, GitHub says there's too many files to upload and tells me to reduce the number I'm uploading.
The crucial part is though, the folder has to be uploaded as a whole, as it itself is within a GitHub repository with other files with different folders in.
That means when I go onto my repository, I need this folder's files to display within the folder, and not separately within the repository. I need all of the files to be within this folder, within the parent repository, excluding the node_modules folder.
For example ->
Parent repository -> Child Directory (what I'm uploading) -> Individual files
I've tried to add the node_modules folder to my gitignore through the following methods:
Adding: node_modules/ to my gitignore file
Writing: echo node_modules >> .gitignore through my terminal
Adding a separate gitignore file within my node_modules file with a * in it
None of them have worked and I can't find any other solutions. For reference I'm using a Mac.
Does anyone have any idea what I'm doing wrong, or how it'd be best to do it?
By default, you do not need to include the node_modules folder in your repositories because the package.json file contains all of your project's dependency information. This means that anyone who clones your repository can run npm install and have the entire node_modules folder without problems.
To solve this you can create your own .gitignore file, creating a new file at the root of your project and renaming it to .gitignore (writing exactly that way). Then you can open it with any text editor and add */node_modules to one of the lines.
This will likely solve your problem.