How to recover files from .gitignore - github

while uploading files to the repository in GitHub, I accidentally click to the button to ignore the files from the upload. Now these files are in a folder called '.gitignore'.
How can I recover these files?
I'm able to see and modify them, I just want to know how to upload them in the repository.
Thanks in advance

I think you misunderstand the concept of .gitignore "folder".
It is instead a text file, with the path of the ignored directories or files.
Consider the following .gitignore file.
foo/bar.txt
foobar/
This will tell git to ignore the directory foobar as well as the file foo/bar.txt, and therefore you won't be able add the files to a commit or push it to a remote repository.
But you can simply remove a file from the list of ignored files and directories by opening the .gitignore file, deleting the line with the corresponding file and saving the .gitignore file. You then should the be able to add the file to a commit and push it to a remote repository.
More information about .gitignore can be found here

Related

Why doesn't this ignore my files recursively?

In my project's root directory there are directories like 'tools':
tools/evaluate/test/
tools/evaluate2
Under test, there are some .py and .csv files. I want to ignore all files except .py, so in my .gitignore, I have this entry:
!tools/**/*.py
I want to recursively ignore all non-python files under tools. What's wrong with that?
if the files you are trying to ignore have been already committed, you need to remove them from the staging area as well, that's done by:
git rm --cached !tools/**/*.py
check the status:
git status
add the files you want to delete to .gitignore i assume manually, i don't know of an automatic way, then finally:
git add .gitignore
git commit -m "Remove unused files"
Two parts are needed here:
# Recursively ignore everything in tools that has an extension:
**/tools/**/*.*
# Except .py files recursively in tools:
!tools/**/*.py

When I push a cpp file to the github repository then an exe file gets added. What can I do so that I don't get those exe files

Whenever I push a cpp file to my github repository an exe file gets added to the repository. I don't want that exe file.How to do that?
you want the file not be tracked across everyone's repositories create a pattern as below in .gitignore file. This file can either be in root directory of you application or a the directory you .cpp and .exe files are in.
*.exe
If you want .exe files to be ignored for only you. Then you can put above pattern in .git/info/exclude
Follow this link for more info:
https://www.atlassian.com/git/tutorials/saving-changes/gitignore

.gitignore file not ignoring .env.local or any other supposed private file

I encountered this error because I once mistakenly committed .env.local before adding it to .gitignore. The answer to it below.
If you're facing something similar and you use the Git GUI in VSCode, just follow these steps:
Open your .env.local file or any file that's having this issue, copy the content to clipboard, and delete the file entirely.
Open your .gitignore file and delete the line that removes that file.
Commit your changes (not necessarily publish).
Now create a new .env.local file (or the file you deleted earlier in your case.)
Switch to your Source Control tab (where you see staged files), right click on this newly created file and add it to .gitignore
Now, it will be ignored for real.

How can I stop cloning my application files on GitHub?

I want to stop cloning my application files to Github, How can I do that completely and remove the circle status on each solution files?
Environment: Visual Studio for Mac
Are you intending to have git ignore those files completely?
You can use a gitignore file (.gitignore) in the root working directory of your project to specify which files to ignore. In there, specify a filename per line in that file, or a whole directory to be ignored (eg: Shared/*).
You'll also need to remove those files from your git repo, since they've already been committed.
Copy-pasting from here:
Unstage the file
git reset HEAD newfile
Remove the file from git
git rm --cached newfile
Deleting the file will count as a commit, so you'll need to git push once you're done.
Also note that the file(s) and their contents will still exist in the git commit history, so this isn't a good idea if the goal is removing files with sensitive info.

Github - gitignore folder doesn't exclude all directory files

I'm using Github Desktop on Windows 10. I have a .gitignore file with which I'd like to ignore everything in the directory, including all subdirectories.
What's frustrating is that most files are excluded, but I'm still getting a few random files that I cannot seem to ignore.
I have a directory, say, My Dir/Sub-dir, I want to ignore. I also want to ignore all files of extension, say, *.swf. Thus, I write this .gitignore file:
My Dir/Sub-dir
*.swf
But, when I go back to Github Desktop, I still get two files similar to the following in the list:
My Dir/Sub-dir/anotherdir/randomfile.xml
My Dir/Sub-dir/animation.swf
What's going on? Is this a bug? Or am I missing something?
EDIT:
Other alternative .gitignores I've tried are:
My*Dir/Sub-dir
*.swf
My\ Dir/Sub-dir
*.swf
My Dir/Sub-dir/
*.swf
/My Dir/Sub-dir
*.swf
EDIT:
So, I've tried the git rm --cached <file> command on my files, and it worked - until one of the files changes again. Github Desktop then once again says they need to be updated.
p.s. It may be that they somehow got indexed in the master branch, as I'm currently in a different branch. Would this cause it? And, if so, how would I eliminate these files from all branches?
To ignore all trees under specific directories, append the trailing slash to the directory:
# Ignore directory at all levels, even if the directory is nested under other directories
My Dir/Sub-dir/
# Ignore the directory only if it exists at the root of your repository
/My Dir/Sub-dir/
# Ignore the sub-directory, no matter where it appears within your repository
Sub-dir/
# Ignore all swf files
*.swf
If you are continuing to experience difficulties, your problem may be that the files you wish to ignore are already indexed by git (via the git add command). If the files are not committed yet, you can remove them from the index with git reset -- 'My Dir/Sub-dir/'. If your files have been committed, you can remove them from the index with git rm --cached <file>.
I guess the whitespace could be a problem. Try
My\ Dir/Sub-dir
or
My*Dir/Sub-dir
This could be a good reference .gitignore entire directory with whitespace in name