gitignore > some ignored files still added to the repository - gitignore

I don't understand why ignored files are still added to the repository. Are there some circumstances when files which are in the .gitignore list, can be still added to the repository
I added directory to the .gitignore before I did anything with the project (project is clean, no trucked or untracked files). Then I built the project. During the build process some files were modified. When the build was done, most of the modified files were ignored, but some were added to the repository. I don't understand this git's selectivity.

Usually, files are added to the index when modified if they were tracked before the .gitignore referenced them.
Try:
git rm --cached -r biz/modules/rest-apis/docs/refAddress
Then control that all files are ignored, by selecting one which was added before:
git check-ignore -v -- biz/modules/rest-apis/docs/refAddress/GET_1.0_v4_addresses.json
You should see a .gitignore rule (no output means: the file is not ignored).

Related

How can I ignore any changes in a particular folder from Git

I want to exclude the changes in all files in a folder Api\Bin*.* and Core\obj*.* into GitHub merging. I dont want to consider that folder while merging the changes. How can I do that Please advise. I have added the following line of code in ignored file from Repository->Setting->Ignored files , but not working . When compile the program , still obj and bin folder files is showed in changes of GitHub
You can add a line in gitingore files following ways
logs/
These lines will ignore the logs folder. Even you can use patterns.
If those files are already tracked, no amount of .gitignore would work.
You need to remove them first (from the Git index, not from your disk)
git rm --cached -r API/bin/
git rm --cached -r Core/obj/
Then check (no commit needed) if you see them in GitHub Desktop.
You can also see if your .gitignore rules apply with:
git check-ignore -v -- Core/obj/<anObjFile>

Git ignore not ignoring directories

I'm trying to ignore obj, bin, debug type files/directories from my Visual studio project. I've followed the advice here:
ignoring any 'bin' directory on a git project
This is not working.
I've pasted the entire git ignore here:
https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
This is not working.
I've tried all sorts of things...
bin/
obj/
*bin/
*obj/
/bin/
/obj/
packages
MyProject/MyProject/obj/
MyProject/MyProject/bin/Debug/
MyProject/MyProject/obj/*
MyProject/MyProject/bin/Debug/*
The directories and their files are still being included when I run a git add. The .gitignore file is added and commited. What am I doing wrong???
EDIT: The files I'm trying to ignore aren't already being tracked. When I run a "git status" there are no pending changes. "nothing to commit, working tree clean". Then I run my VS program which modifies the files in those folders. Then I run another git status and all of the files show up as "modified"...
EDIT2: Does it matter if the files already exist? They are not being tracked but DO exist in the folder structure. When when I run the program they show up again as "modified". Then I have to run a "git checkout ." to remove them all. Then the cycle repeats...
If your file was already been tracked and committed before adding in .gitignore, it won't ignore it. You would require to remove it from index to stop tracking
For file
git rm --cached <file need to remove>
For Folders
git rm -r --cached <folder>
So that would be an issue in your case since Jenkins is still able to see the file in the repo
Hi look at the edit part ,
If you already have any folders in your git index which you no longer wish to track then you need to remove them explicitly. Git won't stop tracking paths that are already being tracked just because they now match a new .gitignore pattern. Execute a folder remove (rm) from index only (--cached) recursivelly (-r).
git rm -r --cached yourfolder
Based on your "Edit 2" above, it sounds like you don't think these have been previously committed, but in reality, they have been. If it shows up as "modified", the git is recognizing the file has changed from the last version it has checked in. If the file was not already committed previously then it would show up as Untracked.
When you are running git checkout on those files, you are telling git to revert those files back to the last version that was checked into git.

.gitignore in subdirectory is getting ignored

I have created a .gitignore file in a subdirectory.
/errors/company/.gitignore
I need it to ignore the file /errors/company/seiten/start/content.phtml.
Content of .gitignore:
seiten/start/content.phtml
But it does still show the file if execute git status. Why?
If you have already commited the .gitignore file, and you still see that file in git status, it is because the file was being tracked from before. You should do the following:
git rm --cached /errors/company/seiten/start/content.phtml
That should do the trick.
PD: I would leave just one .gitignore in the root directory with all the ignored paths and files.

gitignore misses some binary files (DLLs & PEs)

I use the latest version of Github Desktop. My repo consist of a rather large C# solution with many sub-directories and projects. I'd like to ignore all R#-cache files and compiled binaries using the .gitignore file which resides in the root directory of the local repo directory. There are no other gitignore's anywhere in this repo and none in any parent directories. My current gitignore is this:
*.suo
*.user
_ReSharper.*
bin
obj
packages
*.cache
*.pdb
*.dll
*.exe
*.xml
When I made my changes, recompiled and tested everything, I open Github Desktop. It catches almost all files that should be ignored, only some .dlls, .pdbs and .exes are not ignored and always show up as changed:
Now, there are way more binary files in this repo. Only the specific ones in the screengrab are missed.
Is this fixable, and/or can the gitignore be altered to catch all files that it should catch?
Here's what I tried:
Removed and re-cloned the repository
Removed and manually re-created the gitignore
Right-click->Ignore by file extension from within the GitHub Desktop client. This does not work, worse, it creates duplicate masks in the gitignore
Checked for conflicting gitignore's in directories accessible by Github Desktop
Maybe you have files that were already being tracked by git before you modified the .gitignore? Those files (at least in git 1.9.1) aren't ignored when added to a .gitignore.
For example, I created a "test" directory at the root file one of my repos and put a file in it:
mkdir test
echo "abc" > test/x.txt
I added, committed and pushed it. Then I edited .gitignore at the root and added this line:
x.txt
I also made an edit to test/x.txt AND added a new file:
echo "123" >> test/x.txt
mkdir test2
echo "xyz" > test2/x.txt
Now when I run "git status" I see:
modified: .gitignore
modified: test/x.txt
So test2/x.txt is being properly ignored, but test/x.txt is still being tracked.
To force the file to be ignored, you can delete it, add & commit the deletion together with the .gitignore change, then restore the file.

.factorypath added to .gitignore is not taken into account

In .gitignore under the same directory there is
.factorypath
/.factorypath
added for eclipse project. But whenever any change occur in this file it is still visible as modified under git or smartgit.
Any idea why ?
Most likely the file .factorypath was added to git before you excluded it in .gitignore. From the gitignore documentation (http://git-scm.com/docs/gitignore):
NOTES
The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.
To stop tracking a file that is currently tracked, use git rm --cached.
To show files currently tracked by git you can use git ls-files.
As stated in the quote above to stop tracking the file use:
git rm --cached .factorypath.
This will keep your working tree copy of the file but remove it from the index.
It's because the file was previously tracked. With that in mind, this question already has been answered here.