Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore file in Sourcetree not working

I am working on a maven project and I want to ignore the files generated and stored in the /target folder of my project (Evaluation) root folder.In the root of my git repository I have a .gitignore file with the following entries (backend is just a folder which contains the eclipse project Evaluation)

backend/Evaluation/logs/ backend/Evaluation/target/ 

For some reason SourceTree does not ignore the files stored in these two folders and when I compile my project there are some uncommitted changes which are some .class files inside the /target folder.

Why is this happening ? I also tried to change the .gitignore entries to

/backend/Evaluation/logs/**

but it did not work too.

Any ideas ?

like image 722
SteveSt Avatar asked Feb 06 '14 23:02

SteveSt


People also ask

How do I use Gitignore in Sourcetree?

Easiest way to edit the individual, is right click the file. Click Ignore and select the option to ignore just in this repository then you will see a new file called . gitignore in the list. If you have accidentally already added them to the list.

Why is my Gitignore file not working?

Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.

Why is my file not being ignored in Gitignore?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.


1 Answers

Because there is the Sourcetree tag in the question I will answer you how to do this with Sourcetree, it's really simple.

As said before you first have to remove the file from tracking and then make Sourcetree to ignore the file.

  1. Change something in the file so that it is shown to you or select it from the "file status" tab at the bottom of the open repository.
  2. Right click on the file and you see "Ignore...", but it is grayed out because as said above its already in track.
  3. Right click on the file and chose "Stop Tracking"
  4. The file will be shown with a red button which indicates it will be removed (from tracking)
  5. A new entry of the same file will be shown in "file status" with a blue question mark indicates a new file (new because you said remove from tracking in 4)
  6. Right click on the file from 5 and now you see the "Ignore..." is able to choose. Click on it and Sourcetree will put a new entry for the file in the .gitignore file
  7. You can see the .gitignore file if you click on "Setting" on the top right, choose "advanced" and then the first entry is about the ignore file, click on "edit" and it will be open.
like image 62
mfgmicha Avatar answered Sep 16 '22 13:09

mfgmicha