{
  "slug": "Git-Reset--Recovering-From-Unstable-AI-Code-Contributions-tt4ze",
  "title": "Git Reset: Recovering From Unstable AI Code Contributions",
  "subtitle": "",
  "excerpt": "The rise of AI-powered development and \"vibe coding\" has dramatically changed how we build software. Today, tools like GitHub Copilot, ChatGPT, Claude, Cursor, and other AI assistants can generate features, fix bugs, an…",
  "date": "2026-07-20",
  "tags": [
    "git",
    "ai",
    "devops"
  ],
  "readingTime": "3 min",
  "url": "https://www.linkedin.com/pulse/git-reset-recovering-from-unstable-ai-code-mobin-shaterian-tt4ze",
  "hero": "https://media.licdn.com/dms/image/v2/D4E12AQEyjTVzpFXauQ/article-cover_image-shrink_720_1280/B4EZ91u3HkKoAQ-/0/1784386652691?e=2147483647&v=beta&t=AnHKbgNt7mNVd42XPyFroV1Na04aOXYjnd4stLZfxk8",
  "content": [
    {
      "type": "paragraph",
      "html": "The rise of AI-powered development and \"vibe coding\" has dramatically changed how we build software. Today, tools like GitHub Copilot, ChatGPT, Claude, Cursor, and other AI assistants can generate features, fix bugs, and even refactor entire projects in minutes."
    },
    {
      "type": "paragraph",
      "html": "While this has significantly increased developer productivity, it also introduces a new challenge: <strong>not every AI-generated change is correct</strong>."
    },
    {
      "type": "paragraph",
      "html": "AI can misunderstand requirements, introduce subtle bugs, break existing functionality, or make architectural decisions that don't fit your project. Because of this, every AI-generated commit should be reviewed, tested, and validated before becoming part of your production codebase."
    },
    {
      "type": "paragraph",
      "html": "In one of my projects, I accepted several AI-generated commits while experimenting with different configurations. After testing the application, I realized the recent changes had made the project more complicated without solving the original problem."
    },
    {
      "type": "paragraph",
      "html": "Fortunately, Git makes it easy to return to a known good state."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "The Problem"
    },
    {
      "type": "paragraph",
      "html": "My Git history looked something like this:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "* 1bba321 Merge: Disabled Nitro for build\n* 0bd864e Changes\n* 0048e86 Changes\n* 0e915dc Changes\n* a7af924 Changes\n* 34e1189 Changes\n* ba6ecbf Work in progress\n* 02de1b4 Switched to GitHub Pages preset\n* a709621 Changes\n* a40fe57 Changes\n* ecde906 fix: vite working"
    },
    {
      "type": "paragraph",
      "html": "The commit ecde906 was the last stable version of my application. Everything after that point consisted of experiments and AI-generated modifications that I no longer wanted to keep."
    },
    {
      "type": "paragraph",
      "html": "My objective was to:"
    },
    {
      "type": "list",
      "ordered": false,
      "items": [
        "Return the repository to the last stable commit.",
        "Permanently remove all commits created after it.",
        "Update the remote GitHub repository to match the corrected history."
      ]
    },
    {
      "type": "paragraph",
      "html": "At first, I considered using git revert, but that would have created new commits while keeping the unwanted history."
    },
    {
      "type": "paragraph",
      "html": "What I really needed was to rewrite the branch history."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "The Solution"
    },
    {
      "type": "paragraph",
      "html": "First, I switched to the correct branch:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git checkout main"
    },
    {
      "type": "paragraph",
      "html": "Then I reset the branch to the last known good commit:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git reset --hard ecde906e573547ee351dccae515ce2deff5d1c84"
    },
    {
      "type": "paragraph",
      "html": "This command moves the branch pointer, the staging area, and the working directory back to the specified commit, effectively discarding every commit that came after it."
    },
    {
      "type": "paragraph",
      "html": "If those commits have already been pushed to GitHub, the remote branch also needs to be updated:"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Recommended by LinkedIn"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git push --force-with-lease origin main"
    },
    {
      "type": "paragraph",
      "html": "I recommend using --force-with-lease instead of --force because it prevents accidentally overwriting changes pushed by other developers."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "Verifying the Result"
    },
    {
      "type": "paragraph",
      "html": "After resetting the branch, I verified the history:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git log --oneline --graph --decorate"
    },
    {
      "type": "paragraph",
      "html": "Finally, I confirmed that the working tree was clean:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git status"
    },
    {
      "type": "paragraph",
      "html": "If there are still untracked files left over from previous builds, they can be removed with:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git clean -fd"
    },
    {
      "type": "paragraph",
      "html": "Or, to also remove ignored files such as dist, build, or node_modules:"
    },
    {
      "type": "code",
      "lang": "text",
      "code": "git clean -fdx"
    },
    {
      "type": "heading",
      "level": 3,
      "text": "Lessons Learned"
    },
    {
      "type": "paragraph",
      "html": "AI coding assistants are incredible productivity tools, but they should not replace engineering judgment."
    },
    {
      "type": "paragraph",
      "html": "Some practices that have helped me are:"
    },
    {
      "type": "list",
      "ordered": false,
      "items": [
        "Commit frequently so each change is easy to review.",
        "Test every AI-generated change before moving to the next task.",
        "Keep commits small and focused.",
        "Don't hesitate to revert to a known working commit if an experiment goes wrong.",
        "Always use Git as your safety net."
      ]
    },
    {
      "type": "paragraph",
      "html": "As AI-assisted development becomes more common, knowing how to recover from bad changes is becoming just as important as knowing how to generate them."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "Conclusion"
    },
    {
      "type": "paragraph",
      "html": "Using AI to write code is becoming the new normal, but that doesn't mean every generated change belongs in your project's history."
    },
    {
      "type": "paragraph",
      "html": "Treat AI as a pair programmer—not as the final decision-maker. Review its output, run your tests, and commit only changes you trust. And when an experiment doesn't work out, Git provides powerful tools like git reset --hard to restore your repository to a clean, stable state."
    },
    {
      "type": "paragraph",
      "html": "In my case, resetting to the last known good commit and force-pushing the corrected history was the quickest way to get the project back on track."
    }
  ]
}