Can't add new file to repository in EGit

24,115

Solution 1

Alright, I found the error. For some reason I don't really know, there was another .gitignore file ABOVE my Project folder (in repository folder), where my COMPLETE project folder was included. I really don't know how that happened. Of course, this file didn't show up in Eclipse. I tried to add the files on the command line, but gut the error message "File is in .gitignore file". After deleting that file, it worked find. Sorry for the trouble.

Solution 2

Sometimes EGit does not work properly and add to index does not work. In that kind of situations you can go to the root folder of your project (where .git folder is placed) with a file explorer, right click on an empty area inside the folder, select "git bash". This will open the git console for you. Now type "git add path_to_file". This will add the file to the git system for indexing. Now go and refresh your project in eclipse and you will see it is added to the index. This can be used wile resolving conflicts inside eclipse because adding to the index indicates "mark as merged" to the git system by re-adding the merged file.

Also sometimes the "Remove from index" does not work in eclipse, you can do the same thing in that kind of situation: this time write "git remove --cached -f path_to_file". Here do not forget to add "--cached" because otherwise your file will be deleted. -f stands for "force" to force the command. For any folder (directory) to remove from index type "git remove --cached -r -f path_to_folder".

Share:
24,115
Markus
Author by

Markus

Improving customers daily lives with high quality web applications

Updated on October 11, 2020

Comments

  • Markus
    Markus over 3 years

    I'm using EGit with Eclipse Juno. I worked with a local repository and the world was good. Even adding a GitHub repository seemed to be fine. I added it to my local repository under "Remotes", so I can easily push commits to github. But after a while, I noticed that no new files are added to the repository, even if I'm commiting changes. They just are not under version control. They have no symbol, which should mean they are ignored. This is my .ignore

    .gwt
    gwt-unitC
    ache
    Versandanzeige_Web_proto.war
    Versandanzeige_Web.war
    war/ajax
    war/WEB-INF/classes
    war/WEB-INF/deploy
    www-test
    
    • The files are in src, so not even close.
    • The new files don't appear in the Commit-Dialog, even when checking "show untracked files". They don't appear in the Staging-Window.
    • RK -> Team -> "Add to index" doesn't help.
    • The files have the same right and are owned by the same user
    • They definetly dont show up at github

    Any ideas how to fix that? Any additional information needed?

    Update: There are no errors in the error log.

    I do have (HEAD) next to my newest branch.

    More details: I got my trunk T, beginning at T0. At T1, there is a branch A, which has changes to T1. At T2, there is another branch, B. It has no changes to T2. The strange thing: it is not indicated in History view. The master branch is also missing. I can still switch to them. When I do git reflog, there are no entries before or including T2, just everything afterwards.
    I removed the branches without commits: enter image description here enter image description here enter image description here

    The new files are still shown as ignored:
    enter image description here

    Output from command line:

    $ git branch -a: 
    * master 
    maven 
    
    $ git status 
    # On branch master nothing to commit (working directory clean)
    

    About the detached HEAD proposel: I didn't do what is described in the article, checking out an old state and work from that. And I can't see any undone commits.

    Sorry for my bad english, I didn't use it for a while. Please ask for clarification, if I write something hard to understand.

    Update: I could add a file in another folder (/Versandanzeige_Web/war/WEB-INF/lib/gwt-servlet.jar).

  • VonC
    VonC over 11 years
    Excellent. +1. Glad you found the root cause.
  • HanniBaL90
    HanniBaL90 about 8 years
    Good +1. I get exactly the same pb and found unexpectedelly .gitignore at the top which blocked the staging
  • Agu V
    Agu V almost 8 years
    Thanks! it take me a day to find this answer and finally can commit!
  • jumps4fun
    jumps4fun over 7 years
    You found my root cause too! Thanks!
  • kleopatra
    kleopatra over 7 years
    mine was slightly different (I accidentally - don't know how - added the /src/ to the gitignore) - but this answer pointed me into the right direction :-)
  • Splash
    Splash almost 5 years
    Glad it is the same problem for me as well.