Git存储修补与未跟踪的文件 [英] Git stash to patch with untracked files
问题描述
如何让Git存储未跟踪的文件,并将其压入补丁并在另一台计算机中恢复。保存-u功能
git隐藏show -p> patch
git apply patch
但是路径还没有跟踪文件
正常 git stash
创建一个 -u 或 -a
(或其他拼写)创建三投入藏匿袋。第三个提交包含(仅)未追踪的( -u
)或未追踪和忽略/all( -a
)文件,即它会省略所有跟踪的文件。
如果您需要修补程序的形式,诀窍是创建两个修补程序:
- 更改为追踪文件:
git储存显示-p
(到目前为止),加上 - 第三次提交的全部内容,作为补丁。
最简单的方法获得第二个项目符号是 git diff
,第三个项目针对空树进行提交。 Git 每个存储库中始终有一棵空树,其ID是幻数 4b825dc642cb6eb9a060e54bf8d69288fbee4904
。因此,该树与 stash ^ 3
之间的差异将由一系列添加未跟踪文件的git修补程序组成:
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904隐藏^ 3
您可以然后简单地将这两个补丁合并为一个:
git stash show -p> patch
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 stash ^ 3>>补丁
(请参阅上面的最后一个链接,以避免硬编码为空的幻数树。)
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:
- changes to tracked files:
git stash show -p
(what you have so far), plus - the entire contents of the third commit, as a patch.
The 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.)
这篇关于Git存储修补与未跟踪的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!