I have a repository with a file Hello.java
. When I compile it an additional Hello.class
file is generated.
I created an entry for Hello.class
in a .gitignore
file. However the file still appears to be tracked.
I want to know how to make git ignore Hello.class
.
You can use below methods for ignoring/not-ignoring changes in tracked files.
git update-index --assume-unchanged <file>
git update-index --no-assume-unchanged <file>
I have tried the
--assume-unchanged
and also the.gitignore
but neither worked well. They make it hard to switch branches and hard to merge changes from others. This is my solution:When I commit, I manually remove the files from the list of changes
Before I pull, I stash the changed files. And after pull, I do a stash pop.
Step 3 sometimes will trigger a merge and may result in conflict that you need to resolve, which is a good thing.
This allows me to keep local changes that are not shared with others on the team.
If you have already committed the file and you are trying to ignore it by adding to .gitignore file git will not ignore it for that first you have to do below things
if you are staring the project freshly and you want to add some files to git ignore follow below steps to create git ignore file
This webpage may be useful and time-saving when working with .gitignore.
It automatically generates .gitignore files for different IDEs and Operating Systems with the specific files/folders that you usually don't want to pull to your git repository (for instance, IDE-specific folders and configuration files).
Add the following line to .git/info/exclude:
Hello.class