Gitignore Ignore all file except for the files inside a subdirectory - gitignore

I want to add a rule to ignore all apart from the files within a 'Build' folder, but not the folder itself.
I currently have the below which ignores all but the Build folder, but I want only the files within the Build folder, ignoring the folder itself.
# Ignore everything in the root except the Build directory.
/*
!.gitignore
!Build/

It doesn't matter, because git doesn't track folder, only their content.
And if their content is ignored or empty, you won't be able to add their folder, even if that folder is displayed in git status as "untracked".
If Build as some content which isn't ignored, you will be to add said content with the shortcut git add Build: that doesn't mean Build/ is "ignored" or "not ignored": it is just a container.

Related

How do I fix my source control tab on VS 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.

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

Github ignore multiple node_modules

Im having two kind of node_modules in my folders.
One in the root folder, that works fine, but one also in the folder called "html/app" ( so would be html/app/node_modules )
Why wont it ignore it? it adds everything in the node_modules app folder when i do the command "git commit ".
Current .gitignore contains:
/dist
/tmp
/out-tsc
# dependencies
/node_modules
/html/app/node_modules
html/app/node_modules
If I understood your question right - you want to ignore both node_modules folders.
Try to cut that folder from project, then commit it and then return node_modules folder back.
Future commit's would ignore both folders.
EDIT: Probably it works in that way now because of that git already track that folder.

how to rollback the ignore state of a file/folder in git using eclipse

accidently I set the ignore state for a folder in GIT in eclipse.
context-menu on the folder -> team -> ignore.
How can I activate this folder for GIT again ?
I guess it must be team -> add to index, but this doesn't work for me.
any help ?
Click Ctrl+shift+R and type .gitignore in eclipse.
Open the .gitignore file of respective project.
All the ignored file's path will be displayed here.
Now remove the paths of files which you want to unignore and save it.
Again the files will be back to its original stage and can be added to staging area.
Steps to make file unAssumed ignore
If you don't want your files to be ignored then do the following
Go to the file you don't want to be ignored and rightclick it --> Team --> Advanced --> No Assume Unchanged
Please find the same in image
See this bug right now there is no way to find all ignored resource in a git repo using EGIT.
When you do Team context-menu on the folder -> team -> ignore it will automatically create a .gitignore file inside the parent folder and this file is added automatically to git index and will be shown in git staging view.
After committing this file it is difficult to find all ignored resources in a given git repo. Go to your file explorer and search for all .gitignore files inside a git repo and view their content.
In the base directory of the git project, there will be a file called .gitignore (Note the dot at the start of the filename).
This file lists all the files, directories etc that are ignored by git.
Simply edit that file, removing the line which corresponds to the folder you accidentally added.

Is there a way to control what gets into a GitHubs zipball?

Every GitHub repo has the Download ZIP button, but is there a way to control what gets into the final zipball. For example we do not need and hidden files there, or even - unit tests.
Excerpt from Pro Git book:
You can tell Git not to export certain files or directories when
generating an archive. If there is a subdirectory or file that you
don’t want to include in your archive file but that you do want
checked into your project, you can determine those files via the
export-ignore attribute.
For example, say you have some test files in a test/ subdirectory, and
it doesn’t make sense to include them in the tarball export of your
project. You can add the following line to your Git attributes file:
test/ export-ignore
Now, when you run git archive to create a tarball of your project,
that directory won’t be included in the archive.