We do lightening/dev talks every week at work, where a few developers get up and talk about cool projects or anything they think is interesting. One of the recent talks by James MacAuley was about git freeze and git thaw.
The basic idea is that git stash kinda sucks sometimes. To show that, let’s run through an example.
mkdir demo_repo && cd demo_repo git init git commit -m "initial commit" --allow-empty touch README.md touch LICENSE git add README.md
Now if we run
git status, we should see the following:
If we now stash our changes and get the status, we’ll see that LICENSE is still untracked.
git stash git status
This is intentional. As a rule, git will not do anything with files it’s not tracking. This comes in handy for things like password files (arguably should be git ignored) and other files that don’t belong in git.
However, there are times when you want to take the current state of your working directory and stash it. And when you
pop the stash you want everything to go back to the way it was.
Luckily, git will convert any executable file in your path to a custom command. All we need to do it call it
git-<command> and voila!
The goal of git freeze is to create two commits:
WIP [STAGED] and
WIP [UNSTANGED] containing the staged and unstages
Thaw reverses the process by resetting
Both scripts take care to only create/revert commits if they’re needed.
These scripts should be placed in a directory in your
$PATH. Make sure to make them executable.
Going back to our
demo_repo example from earlier, let’s pop that stash.
git stash pop
You should see this again:
Now we can run
git freeze to uh…freeze the current state. And
git thaw to thaw it out again.