How can I make Git stash with untracked files, push it to patch and restore it in another computer.
git stash save -u feature
git stash show -p > patch
git apply patch
But path hasn't untracked files
How can I make Git stash with untracked files, push it to patch and restore it in another computer.
git stash save -u feature
git stash show -p > patch
git apply patch
But path hasn't untracked files
A normal git stash
creates a stash bag that consists of two commits: the index, and the work-tree.
Using -u
or -a
(or their other spellings) creates a three-commit stash bag. The third commit contains (only) the untracked (-u
) or untracked-and-ignored / "all" (-a
) files, i.e., it omits all tracked files.
If you need this in the form of a patch, the trick is to create two patches:
git stash show -p
(what you have so far), plusThe easiest way to get the second bullet item is to git diff
that third commit against an empty tree. Git always has an empty tree in every repository whose ID is the magic number 4b825dc642cb6eb9a060e54bf8d69288fbee4904
. So a diff between that tree, and stash^3
, will consist of a series of git patches that add the untracked files:
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 stash^3
You can then simply combine the two patches into one:
git stash show -p > patch
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 stash^3 >> patch
(See the last link above for a way to avoid hard-coding the magic number for the empty tree. Also, if you just want to view the u
commit, use git show
: git show stash^3
, for instance.)