Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

.gitignore not working as expected

 
Bartender
Posts: 1679
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I created a .gitignore file and put it in the root of my project. Yet, when using eGit in MyEclipse, the .class files, as one example, are still being staged.

Is there a trick on where the .gitignore file needs to be to work?

Missing something here...

Screenshot showing where the .gitignore file is.

Below is the sample .gitignore I copied from an Internet posting.







Thanks,

-- mike
gitignore.jpg
[Thumbnail for gitignore.jpg]
 
Saloon Keeper
Posts: 10423
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have the files already been committed once? .gitignore only affects untracked files.

What happens why you use git add, instead of staging though your IDE?
 
Mike London
Bartender
Posts: 1679
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Have the files already been committed once? .gitignore only affects untracked files.

What happens why you use git add, instead of staging though your IDE?



Success!  

That was exactly the problem, I had already committed the files. So, I just started over with git for this project and it now reads/respects the .gitignore file.

Thanks so much.

-- mike
 
Stephan van Hulst
Saloon Keeper
Posts: 10423
223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For future reference, if you accidentally committed a file that you don't want to keep in your repository, you can take the following steps:

  • git reset --keep <commit before the file was added>
  • git stash push -u -- <file path>
  • git reset --keep <current branch>
  • git rm -- <file path>
  • git commit
  • git stash pop
  •  
    Mike London
    Bartender
    Posts: 1679
    17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Stephan van Hulst wrote:For future reference, if you accidentally committed a file that you don't want to keep in your repository, you can take the following steps:

  • git reset --keep <commit before the file was added>
  • git stash push -u -- <file path>
  • git reset --keep <current branch>
  • git rm -- <file path>
  • git commit
  • git stash pop


  • Yikes!!! Too complicated. I'm more of an IDE Git user. ;)

    In this case, I just started over since I had the code.

    Git has too many sharp edges that can quickly get you into trouble. Well, maybe not an expert like you, but for me definitely.

    Thanks again,

    - mike
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!