We've all been there: you commit code too early, or you realize the last three commits are a mess. Enter git reset. A powerful tool that is often misunderstood. Here is exactly how the three main options work, so you never delete your work by accident again. 1. The Gentle Undo: --soft Use this when you want to keep your work but undo the commit itself. - What it does: Moves the HEAD pointer back to a specific commit. - The State: Your changes are preserved and stay Staged (ready to be committed again). - Use Case: You committed, but forgot to add one file, or you want to squash the last few commits into one. 2. The Default: --mixed If you run git reset without arguments, this is what happens. - What it does: Moves the HEAD pointer back. - The State: Your changes are preserved but moved to Unstaged (Working Directory). - Use Case: You want to keep your work but perhaps break the changes into different commits. 3. The Destructive: --hard - What it does: Moves the HEAD pointer back. - The State: It destroys all changes in the Staging Area and the Working Directory. - Use Case: You completely messed up and want to revert the codebase to exactly how it looked at a previous point. Which one is your most used command? I stick to --soft 90% of the time. If you found this breakdown helpful, repost ♻️ to save a fellow developer from a merge conflict headache. #Git #DevOps #SoftwareEngineering #CodingTips #VersionControl
Mastering Git Reset: Soft, Mixed, and Hard Options Explained
More Relevant Posts
-
🍒 Ever wish you could just grab one specific fix from another branch? We’ve all been there. You’re working on a feature branch, and you realize there’s a critical bug fix or a specific helper function sitting on a different branch. You don't want to merge the entire branch (and all its unfinished chaos). You just want that one specific commit. Enter: git cherry-pick 🍒 🛠️ How it works: git cherry-pick allows you to apply the changes introduced by an existing commit to your current branch. It creates a brand new commit with the same changes and message. 💻 The Workflow: Find the Commit Hash: Switch to the source branch and find the ID of the commit you want. git log --oneline Switch to Target Branch: Move to the branch where you want the fix. git checkout main The Magic Command: git cherry-pick <commit-hash> ⚠️ A Few Pro-Tips: - Avoid over-usage: Frequent cherry-picking can lead to duplicate commits and a messy history. Use it for hotfixes or moving accidental commits to the right branch. - Merge Conflicts: Just like a merge, a cherry-pick can cause conflicts if the code has diverged too much. Git will pause and let you fix them! - The -x Flag: Use git cherry-pick -x <hash> to automatically add a line to the commit message saying "cherry picked from commit..."—great for traceability! #Git Tips #WebDevelopment #SoftwareEngineering #CodingLife #VersionControl #DevOps
To view or add a comment, sign in
-
What is git stash? · GIT STASH is used to temporarily save your uncommitted changes (modified files, staged files) without committing them, so you can work on something else and come back later. Why do we need git stash? You use git stash when: · You are working on a feature · Suddenly need to switch branches · Your changes are not ready to commit · Git does not allow branch switching with uncommitted changes Ever needed to switch branches but had unfinished code? That’s where git stash helps: $ git stash Temporarily saves your uncommitted changes without committing them. $ git stash list Shows all saved stashes. $ git stash pop Restores the latest stash and removes it. $ git stash apply Restores the stash but keeps it saved. $ git stash push -m "message" Save stash with message[Best practice — save stashes with clear messages.] --> Think of git stash as a safe box for work-in-progress code. #Git #DevOps #VersionControl #GitStash
To view or add a comment, sign in
-
Most developers use Git every day, but very few actually understand how it works under the hood. Detached HEAD, lost commits, rebases gone wrong… Git feels scary only because we treat it like a black box. I just published a 5-minute read that breaks Git down to its core: • what a commit really is • why branches are just pointers • how merges, resets, and reflogs actually work • how to recover safely when things go wrong Once you understand Git’s mental model, it stops being magic and starts being predictable. 👉 https://lnkd.in/gcSFRwkr #Git #VersionControl
To view or add a comment, sign in
-
Many developers confuse git restore and git revert, but they solve very different problems. git restore is about fixing your working directory or staging area. It lets you discard local changes or unstage files before they become part of the project history. It does not create a new commit and is typically used when you realize, “I didn’t want to change this file after all.” git revert, on the other hand, is about fixing history safely. It creates a new commit that undoes the effect of a previous commit. This makes it ideal for shared branches, because it preserves the commit history while reversing the changes. In short: * Use git restore to undo local, uncommitted changes * Use git revert to undo a committed change without rewriting history Understanding this distinction helps you avoid mistakes—especially when working in teams. #Git #VersionControl #SoftwareEngineering #Developers #Learning #bongodev #DevOps
To view or add a comment, sign in
-
🛑 Stop dragging and dropping files. Learn Git properly. I used to be scared of the terminal. I relied on SourceTree or GitHub Desktop. But real SDETs are comfortable with the CLI. You don't need to know everything. You just need these 5 Commands to survive 99% of your day: 1. git status (Where am I?) 2. git pull origin main (Get the latest code before you start). 3. git checkout -b feature/login-test (Create your own workspace). 4. git add . + git commit -m "Fixed login script" (Save work). 5. git push (Send it to the team). The "Life Saver" Command: If you messed up everything? git reset --hard (It wipes your changes and goes back to the last clean state. Use with caution! ⚠️) 👇 Question: GUI vs. Command Line? Which team are you on? #Git #VersionControl #SDET #DevOps #SoftwareTesting #TechSkills #AutomationTesting
To view or add a comment, sign in
-
Your git history is a mess and you don't even realize it. Here's what bad commits actually cost you: When something breaks in production, you can't: → Find which commit caused it → Revert cleanly without breaking other things → Understand what changed and why → Review code context from 6 months ago This is why: • "fixed bug" commits are useless (what bug? how?) • Mixing features + fixes in one commit = impossible to revert • Committing commented-out code = future confusion • Large commits = no one reviews them properly The thing most devs ignore: Your commit history IS documentation. Write commits like you're explaining to your future self who's debugging at 2 AM. One logical change per commit. Clear message that answers "why" not just "what". Future you will thank you.
To view or add a comment, sign in
-
🙄Most developers treat git commit messages as throwaway notes: Most of the time, it looks like this: 🔹fix bug 🔹changes 🔹updated code They work until you need to understand why something changed months later. A simple structure makes commits much easier to read and search: ------------ type: short summary (≤ 50 characters) [optional longer explanation] ------------ For example[see image below] A few useful habits: 👉 Keep the first line under 50 characters so it fits cleanly in logs and UIs. 👉 Use the first line as a summary, not a story; details go in the description. 👉 Add a type for instant context, for example: 🔹feat → new feature 🔹fix → bug fix 🔹chore → maintenance 🔹refactor → behavior unchanged, code improved 🔹docs → documentation only This isn’t about strict rules. It is a small default that makes your history easier to scan for you and your team. #Git #DeveloperExperience #Engineering #CleanCode #SoftwareDevelopment
To view or add a comment, sign in
-
-
Git Tip for Beginners: Why Rebase Matters While Your MR/PR Is Waiting for Review 🔄🐙 If you’re new to Git, this situation is very common: 👉 You open a Merge Request / Pull Request 👉 It’s waiting for review ⏳ 👉 Meanwhile, another developer merges changes into main 👉 Suddenly… conflicts 😬 or failing pipelines 🚨 This is where rebasing becomes your best friend. 🤔 What is a rebase (in simple terms)? Rebase means replaying your changes on top of the latest main branch, as if you started your work after the latest merge. Think of it like: 🧱 Taking your bricks 🧹 Cleaning the floor 🏗️ Rebuilding on top of the newest foundation 🚨 What happens if you DON’T rebase? • Your branch becomes outdated • CI pipelines may fail • Reviewers see noisy diffs • Merge conflicts appear at the worst time • Someone has to clean up the mess (maybe you 😅) ✅ Why rebasing while waiting for review is a good habit • Keeps your MR/PR up to date • Reduces merge conflicts • Makes reviewers’ lives easier ❤️ • Keeps the commit history clean • Avoids last-minute surprises before merge 🔁 Typical workflow 1️⃣ Your MR is open and waiting 2️⃣ main gets new commits 3️⃣ You rebase your branch on top of main 4️⃣ Fix conflicts (if any) early 5️⃣ Push and keep the MR green ✅ 🧠 Beginner tip Rebase early. Rebase often. Small conflicts now are much easier than big conflicts later. #Git #GitBeginners #SoftwareEngineering #DevTips #GitHub #GitLab #CleanCode #DeveloperLife
To view or add a comment, sign in
-
#DevOpsSkillBoost_11 🔁 𝐃𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞 𝐂𝐨𝐦𝐦𝐢𝐭 𝐀𝐜𝐜𝐢𝐝𝐞𝐧𝐭𝐚𝐥𝐥𝐲 𝐀𝐝𝐝𝐞𝐝 𝐢𝐧 𝐆𝐢𝐭? 𝐇𝐞𝐫𝐞’𝐬 𝐇𝐨𝐰 𝐈 𝐑𝐞𝐦𝐨𝐯𝐞𝐝 𝐈𝐭 I recently ran into a tricky Git issue — a commit that was 𝐚𝐥𝐫𝐞𝐚𝐝𝐲 𝐦𝐞𝐫𝐠𝐞𝐝 somehow resurfaced and showed up again in my local branch history. 😅 Instead of reverting, I used a cleaner approach because the commit hadn’t been pushed yet. Here’s how I removed the duplicate commit using 𝐠𝐢𝐭 𝐫𝐞𝐬𝐞𝐭 and 𝐢𝐧𝐭𝐞𝐫𝐚𝐜𝐭𝐢𝐯𝐞 𝐫𝐞𝐛𝐚𝐬𝐞👇 🧹 𝐒𝐭𝐞𝐩 1️⃣ — 𝐕𝐞𝐫𝐢𝐟𝐲 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐢𝐭 𝐡𝐢𝐬𝐭𝐨𝐫𝐲 >> git log --oneline Locate the duplicate commit hash and its position. 🔄 𝐒𝐭𝐞𝐩 2️⃣— 𝐑𝐞𝐦𝐨𝐯𝐞 𝐭𝐡𝐞 𝐦𝐨𝐬𝐭 𝐫𝐞𝐜𝐞𝐧𝐭 𝐝𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞 𝐜𝐨𝐦𝐦𝐢𝐭 If the duplicate is the latest commit: >> git reset --hard HEAD~1 This rolls back the last commit completely. ✍️ 𝐒𝐭𝐞𝐩 3️⃣—𝐈𝐟 𝐭𝐡𝐞 𝐝𝐮𝐩𝐥𝐢𝐜𝐚𝐭𝐞 𝐢𝐬 𝐨𝐥𝐝𝐞𝐫, 𝐮𝐬𝐞 𝐢𝐧𝐭𝐞𝐫𝐚𝐜𝐭𝐢𝐯𝐞 𝐫𝐞𝐛𝐚𝐬𝐞 >> git rebase -i HEAD~5 1. delete the duplicate line 2. save and exit This removes the duplicate while keeping the rest of the history intact. 🚨 𝐈𝐦𝐩𝐨𝐫𝐭𝐚𝐧𝐭 𝐍𝐨𝐭𝐞 Use this method only 𝐢𝐟 𝐭𝐡𝐞 𝐜𝐨𝐦𝐦𝐢𝐭𝐬 𝐚𝐫𝐞𝐧’𝐭 𝐩𝐮𝐬𝐡𝐞𝐝. Once pushed, history rewriting can break others’ branches. 🏁 Final Result ✔ duplicate commit removed ✔ clean commit history ✔ no revert commits needed #Git #GitRebase #GitReset #CleanHistory #VersionControl #DevOpsTips #SoftwareEngineering #CodingTips
To view or add a comment, sign in
-
Stop Googling Git commands every time you get stuck. My first commit was a nervous breakdown waiting to happen. Now, I realize you don’t need to memorize the entire documentation—you just need the essentials. Here is the ultimate Git Cheat Sheet I wish I had when I started: 🟢 The Basics (Start Here) ✅ git init → Start a new repository. ✅ git clone [url] → Download a repository. ✅ git status → Check what files are changed. 🟡 The Daily Workflow ✅ git add . → Stage all changes. ✅ git commit -m "message" → Save changes with a note. ✅ git push origin [branch] → Upload to GitHub/GitLab. ✅ git pull → Get the latest changes. 🔵 Branching (Don't break the main code!) ✅ git branch → See your branches. ✅ git checkout -b [name] → Create & switch to a new branch. ✅ git merge [branch] → Combine branches together. 🔴 Oops! (Undo Mistakes) ✅ git checkout -- [file] → Discard changes in a file. ✅ git reset --soft HEAD~1 → Undo the last commit but keep changes. Mastering these 12 commands covers 90% of a Full-Stack Developer's job. 📌 Save this post for your next project. ♻️ Repost to help a connection who is struggling with Git today. #WebDevelopment #Git #Coding #FullStackDeveloper #MERNStack #JasaSolutions #JansherAmeer
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development