Commit your code before asking an AI Assistant to change it. Commit your work with a clear message like "feat: manual implementation of X". Send your prompt to Commit your code before asking an AI Assistant to change it. Commit your work with a clear message like "feat: manual implementation of X". Send your prompt to

AI Coding Tip 001 - Commit Your Code Before Asking For Help From an AI Assistant

A safety-first workflow for AI-assisted coding

Common Mistake ❌

Developers ask the AI assistant to "refactor this function" or "add error handling" while they have uncommitted changes from their previous work session.

\ When the AI makes its changes, the git diff shows everything mixed together—their manual edits plus the AI's modifications.

\ If something breaks, they can't easily separate what they did from what the AI did and make a safe revert.

Problems Addressed 😔

  • You mix your previous code changes with AI-generated code.
  • You lose track of what you changed.
  • You struggle to revert broken suggestions.

How to Do It 🛠️

  1. Finish your manual task.
  2. Run your tests to ensure everything passes.
  3. Commit your work with a clear message like "feat: manual implementation of X".
  4. You don't need to push your changes.
  5. Send your prompt to the AI assistant.
  6. Review the changes using your IDE's diff tool.
  7. Accept or revert: Keep the changes if they look good, or run git reset --hard HEAD to instantly revert.
  8. Run the tests again to verify AI changes didn't break anything.
  9. Commit AI changes separately with a message like refactor: AI-assisted improvement of X.

Benefits 🎯

Clear Diffing: You see the AI's "suggestions" in isolation.

\ Easy Revert: You can undo a bad AI hallucination instantly.

\ Context Control: You ensure the AI is working on your latest, stable logic.

\ Tests are always green: You are not breaking existing functionality.

Context 🧠

When you ask an AI to change your code, it might produce unexpected results.

\ It might delete a crucial logic gate or change a variable name across several files.

\ If you have uncommitted changes, you can't easily see what the AI did versus what you did manually.

\ When you commit first, you create a safety net.

\ You can use git diff to see exactly what the AI modified.

\ If the AI breaks your logic, you can revert to your clean state with one command.

\ You work in very small increments.

\ Some assistants are not very good at undoing their changes.

Prompt Reference 📝

git status # Check for uncommitted changes git add . # Stage all changes git commit -m "msg" # Commit with message git diff # See AI's changes git reset --hard HEAD # Revert AI changes git log --oneline # View commit history

Considerations ⚠️

This is only necessary if you work in write mode and your assistant is allowed to change the code.

Type 📝

[X] Semi-Automatic

You can enforce the rules of your assistant to check the repository status before making changes.

Limitations ⚠️

If your code is not under a source control system, you need to make this manually.

Tags 🏷️

  • Complexity

Level 🔋

[X] Beginner

Related Tips 🔗

  • Use TCR
  • Practice Vibe Test Driven Development
  • Break Large Refactorings into smaller prompts
  • Use Git Bisect for AI Changes: Using git bisect to identify which AI-assisted commit introduced a defect
  • Reverting Hallucinations

Conclusion 🏁

Treating AI as a pair programmer requires the same safety practices you'd use with a human collaborator: version control, code review, and testing.

\ When you commit before making a prompt, you create clear checkpoints that make AI-assisted development safer and more productive.

\ This simple habit transforms AI from a risky black box into a powerful tool you can experiment with confidently, knowing you can always return to a working state.

\ Commit early, commit often, and don't let AI touch uncommitted code.

More Information ℹ️

https://hackernoon.com/git-explained-in-5-levels-of-difficulty?embedable=true

https://www.infoq.com/articles/test-commit-revert/?embedable=true

https://medium.com/@kentbeck_7670/test-commit-revert-870bbd756864?embedable=true

Tools 🧰

GIT is an industry standard, but you can apply this technique to any other version control software.


This article is part of the AI Coding Tip Series.

Market Opportunity
Sleepless AI Logo
Sleepless AI Price(AI)
$0.03969
$0.03969$0.03969
-2.60%
USD
Sleepless AI (AI) Live Price Chart
Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact [email protected] for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.

You May Also Like

Ethereum unveils roadmap focusing on scaling, interoperability, and security at Japan Dev Conference

Ethereum unveils roadmap focusing on scaling, interoperability, and security at Japan Dev Conference

The post Ethereum unveils roadmap focusing on scaling, interoperability, and security at Japan Dev Conference appeared on BitcoinEthereumNews.com. Key Takeaways Ethereum’s new roadmap was presented by Vitalik Buterin at the Japan Dev Conference. Short-term priorities include Layer 1 scaling and raising gas limits to enhance transaction throughput. Vitalik Buterin presented Ethereum’s development roadmap at the Japan Dev Conference today, outlining the blockchain platform’s priorities across multiple timeframes. The short-term goals focus on scaling solutions and increasing Layer 1 gas limits to improve transaction capacity. Mid-term objectives target enhanced cross-Layer 2 interoperability and faster network responsiveness to create a more seamless user experience across different scaling solutions. The long-term vision emphasizes building a secure, simple, quantum-resistant, and formally verified minimalist Ethereum network. This approach aims to future-proof the platform against emerging technological threats while maintaining its core functionality. The roadmap presentation comes as Ethereum continues to compete with other blockchain platforms for market share in the smart contract and decentralized application space. Source: https://cryptobriefing.com/ethereum-roadmap-scaling-interoperability-security-japan/
Share
BitcoinEthereumNews2025/09/18 00:25
FCA komt in 2026 met aangepaste cryptoregels voor Britse markt

FCA komt in 2026 met aangepaste cryptoregels voor Britse markt

De Britse financiële waakhond, de FCA, komt in 2026 met nieuwe regels speciaal voor crypto bedrijven. Wat direct opvalt: de toezichthouder laat enkele klassieke financiële verplichtingen los om beter aan te sluiten op de snelle en grillige wereld van digitale activa. Tegelijkertijd wordt er extra nadruk gelegd op digitale beveiliging,... Het bericht FCA komt in 2026 met aangepaste cryptoregels voor Britse markt verscheen het eerst op Blockchain Stories.
Share
Coinstats2025/09/18 00:33
Monero Blows Past Its All-Time Price High as It Eyes a Top 10 Position

Monero Blows Past Its All-Time Price High as It Eyes a Top 10 Position

The privacy-focused crypto asset monero ( XMR) has been on a tear lately, with the digital currency clocking a new all-time high on Sunday, Jan. 11, 2026. Monero
Share
Coinstats2026/01/12 06:23