We’ve all been there: You use 𝙜𝙞𝙩 𝙧𝙚𝙨𝙚𝙩 --𝙝𝙖𝙧𝙙 to wipe away a mistake, only to realize you accidentally deleted some valuable work along with it. Because it’s a "hard" reset, your changes vanish from the folder and no longer appear in 𝙜𝙞𝙩 𝙡𝙤𝙜. For many, this is the "panic" moment. 𝗧𝗵𝗲 𝗦𝗲𝗰𝗿𝗲𝘁: Your work isn't gone; your branch just stopped pointing to it. In the video below, I demonstrate how to use a "Double Reset" strategy to recover "lost" commits: 𝗧𝗵𝗲 𝗪𝗼𝗿𝗸𝗳𝗹𝗼𝘄: 1. 𝗧𝗵𝗲 𝗦𝗰𝗲𝗻𝗮𝗿𝗶𝗼: I have a "Good Commit," followed by a second commit with changes I want to keep. 2. 𝗧𝗵𝗲 𝗠𝗶𝘀𝘁𝗮𝗸𝗲: I run 𝙜𝙞𝙩 𝙧𝙚𝙨𝙚𝙩 --𝙝𝙖𝙧𝙙 to go back to the first commit. My second commit "disappears." 3. 𝗧𝗵𝗲 𝗗𝗶𝘀𝗰𝗼𝘃𝗲𝗿𝘆: 𝙜𝙞𝙩 𝙡𝙤𝙜 shows nothing, but 𝙜𝙞𝙩 𝙧𝙚𝙛𝙡𝙤𝙜 shows the entire history of where my HEAD has been. 4. 𝗧𝗵𝗲 𝗥𝗲𝗰𝗼𝘃𝗲𝗿𝘆: I find the hash of the "lost" commit in the reflog and run 𝙜𝙞𝙩 𝙧𝙚𝙨𝙚𝙩 --𝙝𝙖𝙧𝙙 again but this time pointing forward to the lost work. A hard reset feels destructive, but Git’s internal journal (reflog) is almost always recording in the background. If you over-reset, don't panic. Just reflog, find your hash, and reset back to safety. #Git #SoftwareEngineering #ProgrammingTips #Coding #GitHub #SoftwareEngineerIntern #Tutorial
More Relevant Posts
-
5 Git commands I wish someone had shown me on day one. Everyone teaches git add, commit, push. Nobody teaches the commands that actually save you when things go wrong. 1. git stash Shelve your uncommitted work without losing it. Switch branches cleanly, come back, and run git stash pop. Done. 2. git log --oneline --graph A visual map of your entire branch history in the terminal. Essential when you're debugging "how did the codebase get into this state." 3. git bisect Binary search through your commit history to find the exact commit that introduced a bug. Sounds complex — takes 5 minutes to learn and saves hours. 4. git commit --amend Fix your last commit message or add a forgotten file before pushing. No more embarrassing "oops" commits cluttering the history. 5. git reflog Your ultimate safety net. Every HEAD movement recorded. Accidentally deleted a branch? Reset too hard? Reflog can bring it back. Almost nothing in Git is truly gone. Bonus: git cherry-pick [hash] — Apply one specific commit from another branch without merging everything else. Surgical and underused. Bookmark this for the next time something breaks at 11 PM. Which of these took you the longest to discover? #Git #CodingTips #DevProductivity #SoftwareEngineering #DevLife
To view or add a comment, sign in
-
-
93% of developers use Git. Are you one of them who actually understands it? Most people just use git push and pray. 😅 Here's a complete Git + GitHub cheat sheet that every developer should know: 🔧 Configure — Set up your identity before anything else git config --global user.name & git config --global user.email 📦 Stage & Commit — Files go untracked → staged → committed git add → git commit -m "your message" 🌿 Branches — Work in isolation without breaking the main project git checkout -b branch-name 🔀 Merge — Combine your branch back to master when done git merge branch-name ☁️ Push & Pull — Sync with GitHub seamlessly git push origin & git pull origin ⏪ Revert vs Reset — git revert keeps history safe. git reset wipes it. Know the difference before you regret it! ✏️ Amend — Fix your last commit without creating a new one git commit --amend -m "corrected message" 💡 Git is not just a tool — it's your safety net, your time machine, and your team's backbone. Master the basics and you'll never lose your code again. 🚀 Save this post for later. Share it with a beginner who needs it. ♻️ #Git #GitHub #VersionControl #WebDevelopment #100DaysOfCode #DevTips #Programming #OpenSource #LearnToCode #Coding
To view or add a comment, sign in
-
Which Git Error Haunts You Most? Every developer has a Git error that made their stomach drop. Here are the four most common ones I hear about. Which has happened to you? 👇 🔴 A: "rejected - non-fast-forward" (You tried to push and Git said no. You force-pushed. Something broke.) 🟠 B: "You are in detached HEAD state" (You have no idea what this means. You close the terminal and reopen it.) 🟡 C: "CONFLICT (content): Merge conflict in..." (Multiple files. You spend two hours resolving something that should have taken ten minutes.) 🟢 D: "fatal: refusing to merge unrelated histories" (You have never seen this before. You do not know what "unrelated histories" means.) Vote in the comments. And if yours is not on the list, tell me what it is. I will spend the next week writing posts that explain each one properly. Not "here is the fix." Here is why it happened, what Git is actually telling you, and how to never be surprised by it again. 📚 These are all covered in my upcoming book "Stop Breaking Git". But first; your vote. Comment A, B, C or D. Most voted = I write a deep-dive thread tomorrow. #Git #SoftwareDevelopment #Programming #WebDev #100DaysOfCode
To view or add a comment, sign in
-
⚠️ Git Rebase is Powerful — But It Can Break Your Team's Workflow! In Continuation to my previous post on Git Rebase, Today lets look into everything you need to know about using rebase safely 👇 --- 💣 The Hidden Danger of Rebase: When you rebase a shared branch: → Git creates NEW commit hashes → Your teammates still have the OLD hashes → Their push gets REJECTED → They pull to sync and get DUPLICATE commits → History becomes a total nightmare 😤 --- 🔥 How to Fix It Step-by-Step: 1️⃣ Don't do git pull when your push gets rejected ❌ 2️⃣ git fetch origin ✅ 3️⃣ git rebase origin/feature 4️⃣ Fix conflicts in affected files → Stage the files using git add 5️⃣ git rebase --continue 6️⃣ git push — it works now! ✅ --- 📌 The Rules to Live By: ✅ Rebase only YOUR local private branches ✅ Always fast-forward master after rebasing in case you use it. ❌ Never rebase branches others are working on ❌ Never rebase master/main directly --- Rebase is not scary — you just need to know WHEN to use it! Save this post for the next time your team hits a rebase conflict. 🔖 #Git #VersionControl #GitHub #SoftwareEngineering #DevOps #WebDevelopment #Programming #TechTips #100DaysOfCode
To view or add a comment, sign in
-
🚨 Git told me "Aborting" today. And honestly? I deserved it. 😅 Here's the story — I was deep in my project, making changes , tweaking things, and feeling productive. Then I ran git pull. And Git hit me with this: ❌ "error: Your local changes to the following files would be overwritten by the merge. Please commit your changes or stash them before you merge. Aborting." For a moment I just stared at the terminal. 😶 But then I realised Git wasn't being cruel. It was being careful. It was protecting my work from being wiped out by the incoming changes. So instead of forcing the pull and losing everything, I did this: → Stashed my local changes with git stash → Created a fresh branch with git checkout -b feature/my-branch → Reapplied my work with git stash pop → Committed, pushed, and opened a Pull Request on GitHub Clean. Safe. Professional. ✅ The biggest mindset shift for me as a developer? Stopping to think before running commands blindly. Git conflicts aren't failures — they're checkpoints that force you to slow down and be intentional about your code. If you're a developer who has panicked at "Aborting" before, save this. You'll need it. 🙌 ♻️ Repost if this helped someone on your network! #Git #GitHub #WebDevelopment #React #Developer #100DaysOfCode #DevLife #OpenSource #CodingJourney #PullRequest #GitTips #Programming #SoftwareEngineering #Debugging #TechCommunity
To view or add a comment, sign in
-
Git confused me for YEARS… until I finally understood this If you're learning Git the hard way, this might save you a lot of frustration. 👉 Pro tip: Start with the command line. Visual tools are nice but when you're SSH’d into a server, they won’t save you. 🔧 When Git gets weird (and how to fix it) 1️⃣ Committed to the wrong branch? git reset HEAD~1 git checkout correct-branch git add . git commit -m "message" 2️⃣ Need to undo your last commit? # Keep your changes git reset --soft HEAD~1 # Delete everything (be careful ⚠️) git reset --hard HEAD~1 3️⃣ Pushed something you shouldn’t have? # If no one pulled yet git reset --hard HEAD~1 git push --force ⚠️ # Safer option (if others already pulled) git revert HEAD git push 4️⃣ Everything is broken and you want a fresh start? git fetch origin git reset --hard origin/main 💡 Git isn’t hard, you just need the right mental model. Most developers struggle not because Git is complex… but because no one explains these real-world scenarios. #Git #WebDevelopment #SoftwareEngineering #Developers #Programming #TechTips
To view or add a comment, sign in
-
🛑 Stop letting your Git Stash become a "black hole" of forgotten code. We’ve all been there: you’re mid-feature, a critical bug pops up, and you git stash your work to pivot. Fast forward a week, and you have 15 stashes named "WIP" with no idea what’s inside. 😅 A clean repository is a productive repository. Here is your quick guide to mastering stash hygiene: ✅ git stash clear — Wipe the slate clean. Use with caution, as this removes every stash in your repo permanently. ✅ git stash drop stash@{n} — Need to delete just one specific experiment? Find the index with git stash list and drop only what you don't need. ✅ git stash pop — Apply your latest changes and delete the stash entry in one move. Perfect for short-term context switching. 💡 Pro-Tip: Always use git stash push -m "message" instead of just git stash. How do you manage your temporary changes? Do you prefer stashing or temporary "WIP" commits? Let's discuss below! 👇 #Git #SoftwareEngineering #WebDevelopment #ProgrammingTips #DevOps
To view or add a comment, sign in
-
-
🚀 𝙎𝙩𝙤𝙥 𝙡𝙤𝙨𝙞𝙣𝙜 𝙬𝙤𝙧𝙠. 𝙎𝙩𝙖𝙧𝙩 𝙨𝙩𝙖𝙨𝙝𝙞𝙣𝙜 𝙞𝙩. Ever been in the middle of a feature when your lead says, "Hey, fix this urgent bug NOW"? Most devs either commit half-baked code. There's a better way - git stash. What git stash does for you: 🔀 𝗠𝗶𝗴𝗿𝗮𝘁𝗲 𝗯𝗲𝘁𝘄𝗲𝗲𝗻 𝗯𝗿𝗮𝗻𝗰𝗵𝗲𝘀 𝗳𝗿𝗲𝗲𝗹𝘆 — Save your work-in-progress instantly and switch branches without a single lost line. Come back anytime, pick up right where you left off. 📜 𝗞𝗲𝗲𝗽 𝗮 𝗰𝗹𝗲𝗮𝗻 𝗰𝗼𝗺𝗺𝗶𝘁 𝗵𝗶𝘀𝘁𝗼𝗿𝘆 — No more "WIP", "temp", or "fix fix fix" commits polluting your log. Stash keeps your half-done work off the timeline until it's ready. 👥 𝗪𝗼𝗿𝗸 𝘀𝗺𝗼𝗼𝘁𝗵𝗹𝘆 𝗶𝗻 𝘀𝗵𝗮𝗿𝗲𝗱 𝗯𝗿𝗮𝗻𝗰𝗵𝗲𝘀 — Multiple devs on the same branch? Stash your changes -> pull latest -> apply back. Zero conflicts, zero drama. The commands you'll actually use: git stash -> save everything git stash pop -> restore & remove from stash git stash list -> see all stashes git stash apply stash@{1} -> pick a specific one git stash drop -> clean up old stashes "Commit to clarity. Stash the chaos." #git #devtips #programming #100DaysOfCode #learning
To view or add a comment, sign in
-
-
We've all opened git blame and seen our own name staring back at us. The commit message says "fix". The date says eight months ago. The code says something you can no longer explain. Git 2.53.4 finally has a command for this situation. I wrote about it 👇 https://lnkd.in/ess-bt3i
To view or add a comment, sign in
-
When using claude dispatch, note that the work that it does occurs in git worktrees. If you use it against an existing claude code repo, it might be a little confusing at first. For me, what was most confusing was returning to my mac after using dispatch and finding that the clone was no longer a git repo. Instead, I found the work in .claude/worktrees/ From there, I reviewed the changes and had claude commit and merge and then everything returned to normal. Now, after this practical experience, I have a better understanding of git worktrees. As usual, it is worthwhile to try something out and get familiar with it before you actually need to use it.
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