.gitignore file in Sourcetree not working

前端 未结 8 1336
走了就别回头了
走了就别回头了 2021-01-30 01:23

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

相关标签:
8条回答
  • 2021-01-30 01:51

    I found that by deleting the repository, then having the .gitignore file in the folder when the repository is recreated the ignore file is respected.

    0 讨论(0)
  • 2021-01-30 01:52

    In addition to the answers already provided above, also note that the .gitignore file will not work if it is not in the root folder.

    I had a project where .gitignore was here /projectname/.gitignore and therefore was not being read. So I moved it to /.gitignore and all was well again.

    0 讨论(0)
  • 2021-01-30 01:54

    I had a problem with bin folder being tracked (entire folder).

    So here are the quick steps (more visual, as I'm more of a visual type of person):

    1. Just for security purposes, I zipped entire bin folder
    2. Move it to desktop
    3. Move (current) .gitignore to the desktop as well
    4. Delete entire BIN folder
    5. Commit changes (via favourite git commit tool)
    6. Commit, push, done!
    7. Go back to the basic project's folder
    8. Move back the .gitignore file
    9. Optional - move back (unzip) the bin folder as well.
    10. As a result, you will see that the git tool is no longer tracking changes from the bin folder.

    I hope this helps someone.

    0 讨论(0)
  • 2021-01-30 02:02

    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.
    0 讨论(0)
  • 2021-01-30 02:05

    This worked for me:

    git update-index --assume-unchanged some.file
    
    0 讨论(0)
  • 2021-01-30 02:09

    If the files have already been added or committed to your Git repository, you must first stop tracking them before they will be ignored by .gitIgnore.

    To stop tracking files in SourceTree:

    Right-click on files. Choose "Stop Tracking".
    (this won't delete your files, it just stops tracking them)

    To stop tracking files from Command-line:

    git rm --cached example.txt
    
    0 讨论(0)
提交回复
热议问题