Skip to content

Instantly share code, notes, and snippets.

@jamesWalker55
Last active October 9, 2025 10:52
Show Gist options
  • Save jamesWalker55/b8cea5145ec167e0eb32b1168bdd3c3b to your computer and use it in GitHub Desktop.
Save jamesWalker55/b8cea5145ec167e0eb32b1168bdd3c3b to your computer and use it in GitHub Desktop.
If you have many local changes that should not be commited, stash those files then re-apply the stash to local changes. Then use this script to stage everything that is not in the stash.
# This relies on the latest stash having untracked files
# Always create stash with:
#
# git stash -u
#
# Always apply your stash with:
#
# git stash apply
#
# Never do `git stash pop`!
# create checkpoint
git tag -f asd-start -m "asd-start"
# create full commit
git add *
git commit -m "asd-full"
git tag -f asd-full -m "asd-full"
git checkout asd-start
# create stash commit
git checkout asd-start
git stash apply
git add *
git commit -m "asd-stash"
git tag -f asd-stash -m "asd-stash"
git checkout asd-start
# create diff commit from full -> stash
git checkout asd-full
git reset --soft asd-stash
git commit -m "asd-newchanges"
git tag -f asd-newchanges -m "asd-newchanges"
git checkout asd-start
# [!] this may have merge conflicts [!]
git checkout asd-start
git cherry-pick asd-newchanges
# resolve merge conflicts now!! (if any)
# continue cherry-pick and don't prompt for new commit message
git -c core.editor=true cherry-pick --continue
git tag -f asd-newchanges-isolated -m "asd-newchanges-isolated"
git checkout asd-start
# final step:
git checkout asd-newchanges
git reset --mixed asd-newchanges-isolated
git reset --soft asd-start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment