Oops - How to Undo Anything
29%
Put Your Work on Pause
Sometimes you're in the middle of working on something, but you need to switch to a different task quickly like fixing a bug in another branch, or maybe you just want to save your progress without committing it yet. You don't want to commit half-finished work, but you also don't want to lose what you've done.
This is where git stash comes in.
A stash takes your uncommitted changes, saves them aside, and gives you a clean working directory. Later, you can bring those changes back.
Working Directory Stash
ββββββββββββββββββββ git stash ββββββββββββββββ
β uncommitted βββββββββββββββββββ> β saved β
β changes β β changes β
β β <βββββββββββββββββββ β
ββββββββββββββββββββ git stash pop ββββββββββββββββ
(clean)
Let's simulate this. Add a division function but don't commit it:
cat << 'EOF' > calculator.py
# calculator.py - A simple calculator
def add(a, b):
"""Add two numbers and return the result."""
return a + b
def subtract(a, b):
"""Subtract b from a and return the result."""
return a - b
def multiply(a, b):
"""Multiply two numbers and return the result."""
return a * b
def divide(a, b):
"""Divide a by b and return the result."""
if b == 0:
return "Error: Cannot divide by zero"
return a / b
# Try it out
result_add = add(5, 3)
result_sub = subtract(10, 4)Learn Git in a Day
Everything you need, nothing you don'tEnroll now to unlock all content and receive all future updates for free.
Unlock now Β $9.99$7.49Learn More
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
