Monday, 30 June 2025

Revert a Specific File Committed that Pushed to Remote Git

You want to undo changes to just one file, even though the commit has already been pushed.

Option 1: Revert the file to the previous version and commit again (Safe & Recommended)

-----------------------------------------------------------------------

1. Revert the file to the version from the previous commit:

git checkout HEAD^ -- path/to/your/file

2. Stage the reverted file:

git add path/to/your/file

3. Commit the change:

git commit -m "Revert file to previous version"

4. Push to remote:

git push

Tip: You can use a specific commit hash instead of HEAD^

Option 2: Reset file to a specific older commit version (Safe if targeted)

------------------------------------------------------------

1. View commit history for the file:

git log path/to/file

2. Reset the file to that commit's version:

git checkout <commit-hash> -- path/to/file

3. Commit and push:

git add path/to/file

git commit -m "Revert file to specific commit version"

git pushOption 3: Revert the whole commit (only if the commit changed only this file)

-----------------------------------------------------------

git revert <commit-hash>

git push

Avoid:

------

Avoid using 'git reset --hard' and 'git push -f' on shared branches.

Always use a clean commit to revert individual file changes on shared remotes.

Friday, 30 May 2025

My sql do alter table on production -Percona's

 pt-online-schema-change \

  --alter "ADD INDEX idx_project_doc_filter (

    external_app_id,

    user_id,

    date_created DESC,

    design_name,

    subject_folder_id,

    listing_id,

    date_updated

  )" \

  --user=your_user \

  --password=your_pass \

  --host=your_host \

  --execute

Friday, 9 May 2025

spring swagger documentation

 https://springdoc.org/

<dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.5.0</version> </dependency>

Thursday, 10 April 2025

AWS credential provider types

 

ProviderUse CaseNotes
StaticCredentialsProviderManual credentialsDon't use in production
EnvironmentVariableCredentialsProviderEnv varsGood for local/prod
SystemPropertyCredentialsProviderJVM propertiesUseful in CI/CD
ProfileCredentialsProviderNamed profiles in AWS config filesGreat for multi-account setups
DefaultCredentialsProviderLet AWS figure it out👍 Preferred way
InstanceProfileCredentialsProviderIAM role on EC2Secure and scalable
ContainerCredentialsProviderIAM role on ECS/EKSWorks well in containers

Tuesday, 8 April 2025

Thursday, 20 March 2025

Use velocity template in spring 5

Step 1

 @Configuration

public class VelocityConfig {


    @Bean

    public VelocityEngine velocityEngine() {

        Properties properties = new Properties();

        properties.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");

        properties.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());


        VelocityEngine velocityEngine = new VelocityEngine();

        velocityEngine.init(properties);

        return velocityEngine;

    }

}


Step 2

public class VelocityTemplateProcessor {

    private final VelocityEngine velocityEngine;


    public VelocityTemplateProcessor(VelocityEngine velocityEngine) {

        this.velocityEngine = velocityEngine;

    }


    public String processTemplate(String templateName, Map<String, Object> model) {

        Template template = velocityEngine.getTemplate(templateName);

        VelocityContext context = new VelocityContext(model);


        StringWriter writer = new StringWriter();

        template.merge(context, writer);

        return writer.toString();  // Return final processed content

    }

}


Step 3

@RestController

public class MyController {

    private final VelocityTemplateProcessor velocityProcessor;


    public MyController(VelocityTemplateProcessor velocityProcessor) {

        this.velocityProcessor = velocityProcessor;

    }


    @GetMapping("/welcome")

    public String generateWelcomeMessage() {

        Map<String, Object> model = new HashMap<>();

        model.put("username", "Pawan");


        return velocityProcessor.processTemplate("templates/welcome.vm", model);

    }

}


step 4

Located in src/main/resources/templates/welcome.vm:

perl