I have a rule in the .gitignore file of my GitHub repo to ignore all .jar files that will come up during development.
Now, I am working on an upgrade task, which has some Jar files that need to go into the remote repository. I can remove the rule from the .gitignore file but I will have to cherry-pick each relevant jar file among 100 more Jars that were been ignored previously.
The work I am doing is isolated to a few folders and subfolders on the repo.
There must be some easier way to achieve this goal. Googling won't help because I don't even know what I should be searching for.
From the answer to this question https://stackoverflow.com/a/60558023/14310825, I have tried to try to override that rule. For example, if my project directory looks like this.
This is the real folder structure of my local, .git and .gitignore are present inside the custom folder [invisible here]
and my .gitignore looks like this:
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
!solr-commerce-plugins*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
##############################
## Eclipse
##############################
.metadata
*.tmp
*.bak
*.swp
*~.nib
.loadpath
.factorypath
eclipsebin
##############################
## OS X
##############################
.DS_Store
##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
*build.number
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar
##############################
## SAP CC
##############################
/core-customize/c4c-integration
/core-customize/licenses
/core-customize/hybris/temp
/core-customize/installer
/core-customize/hybris/log
/core-customize/hybris/data
/core-customize/hybris/bin/platform
/core-customize/hybris/bin/modules
/core-customize/hybris/bin/dummy.txt
/core-customize/README
/core-customize/SIGNATURE.SMF
/core-customize/build-tools
*classes/
/core-customize/hybris/bin/custom/avantor*/**/*jalo/
*addonsrc/
*addons/
*addontestsrc/
*_ui/
!*rhino-1.7.7.jar
!*wro4j-core-1.8.0.jar
*commonwebsrc/
*gensrc/
/core-customize/hybris/config/backup
/core-customize/hybris/config/tomcat
/core-customize/hybris/config/solr/instances/default/*
!/core-customize/hybris/config/solr/instances/default/configsets
core-customize/hybris/config/solr/instances/default/configsets/default/conf/*
!/core-customize/hybris/config/solr/instances/default/configsets/default/conf/*.xml
!/core-customize/hybris/config/solr/instances/default/configsets/default/conf/lang
/core-customize/hybris/config/orbeon
/core-customize/hybris/config/licence
/core-customize/hybris/config/security
/core-customize/hybris/config/local.properties
# Exclude build-regenerated misc files
/core-customize/hybris/bin/custom/**/build.xml
extensioninfo.xsd
beans.xsd
items.xsd
platformhome.properties
*-webtestclasses.xml
*-testclasses.xml
.lastupdate
core-customize/hybris/bin/custom/avantor/avantorcore/.classpath
*node_modules/
*.rush/
*dist/
\custom\otmmaddon\bin\otmmaddonserver.jar and \custom\otmmaddonbackoffice\bin\otmmaddonbackofficeserver.jar
are the jars I need to add to the commit along with two more Jar file for OTMMsmartedit and OTMMws having similar folder structure
what I did was add this two lines on the git ignore
!\custom\otmmaddon\bin\**\.jar
!\custom\otmmaddonbackoffice\**\*.js
Git is still ignoring the files.
Please note that I am working on a Java-Springboot project, the above is an example of what issues I am facing and what I am expecting. I do not want to ignore any .jar files in some directories of my repo

Transcribing edited forms of my comments ([1] [2] [3]) into an answer.
It's interesting that the text of the question mentions
.jarfiles but the example only covers.jsand.cssfiles.