Git - Reset Commits


Git - Reset Commits

Git - Reset Commits

Remove the last commit/commits using Reset

Steps to remove the last commit/commits

Step 1 Checkout to master

git checkout master

Note : This could be done in any branch. For this example, master branch is used.

Step 2 - Get the commits history

git log

You will end up with list of commits that you made as follows.

logs

Step 3 - Reset

Step 3.1 - Copy the commit-hash that you want to reset

All the commits that top of the selected commit-hash (not including the entered commit-hash), will be deleted.

Step 3.2 - Hard reset to go back to early stage

git reset <commit-hash> --hard

Options to reset

  1. Soft Reset
git reset <commit_hash> --soft
  1. Mixed Reset
git reset <commit_hash>

#OR

git reset <commit_hash> --mixed
  1. Hard Reset
git reset <commit_hash> --hard

Step 3 - Force push to the repository

git push <remote> master --force

<remote> can be any remote, origin is the default.

NOTE : Be careful when removing the previous commits, there is no going back once you did these changes.

Rebase

We can also re-write history commits in a different place

git rebase <commit-hash>

Revert

Inverse the changes from history and create a new commit

git revert <commit-hash>

Related Post:

Why Python for Production Services

Vector Deployment Patterns

Vector Aggregator — Transform and Route

Vector Agent — Lightweight Log Collection

HashiCorp Vault — Centralized Secret Management

Vault Auth Methods — Token vs AppRole

Unit Tests for Business Logic

Test Coverage and CI Integration

Docker Swarm Deployment

Why Structured Logging Matters

structlog — JSON Logging with Context

Secret Workflow — Local to Production

Scheduled Security Scans

Production Operations Runbook

pytest — Fixtures, Conftest, and Async Testing

Pydantic — Request & Response Validation

Prometheus Metrics — RED Method

Project Structure with pyproject.toml

Pre-Commit Hooks for Security

Auto-Instrumentation for FastAPI

OpenTelemetry — Traces, Spans, and Context

Marathon/Mesos Deployment

Log Rotation and Disk Management

End-to-End Pipeline

Kubernetes Deployment

Kafka — Durable Log Transport

Jaeger — Visualizing Distributed Traces

Integration Tests for API Endpoints

Health Checks and Readiness Probes

Graceful Shutdown

GitHub Actions CI Pipeline

FastAPI — Async-First HTTP Framework

Error Handling & Response Models

Elasticsearch + Kibana — Search and Visualize

Dual Output — Stdout and File Logging

Docker — Containerize from Day One

Docker Compose Deployment

Dependency Updates and Maintenance

Dependency Auditing with pip-audit

Request-Scoped Logging with Correlation IDs

Container Security with Trivy

Environment-Based Config with pydantic-settings

Async Database Operations

API Versioning Strategies

RESTful Route Design with FastAPI Router

K8s Contributor Playground, Learning by Contributing

Adding Try in PWD button to README file

Docker Issues

Jenkins - Upgrade Jenkins

SED

Jenkins - Schedule

AWS EBS Volmes - Create and attach the EBS volume with mounting

Elasticsearch - Dumping documents from multi-node to single node

CICD Jenkins - Send email with default content

Linux - sed command

Arachni - VAPT Tool

VAPT - Vulnerability Assessment and Penetration Testing