git 我怎样才能用我藏起来的东西格式化补丁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2160638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I format patch with what I stash away
提问by silverburgh
In git, I stash away my changes. Is it possible that I can create a patch with what I stash away? And the apply that patch in some other repository (my co-worker's)?
在 git 中,我隐藏了我的更改。我可以用我藏起来的东西创建一个补丁吗?并在其他一些存储库(我的同事的)中应用该补丁?
I know 'git format-patch -1' but I think that is for what I have committed. But I am looking for the same thing for changes I stashed away?
我知道 'git format-patch -1' 但我认为这是我所承诺的。但是我正在为我藏起来的变化寻找同样的东西?
And how can I apply a patch in other repository?
以及如何在其他存储库中应用补丁?
回答by Greg Hewgill
回答by calvinf
This answer provides info about both saving the patch and applying it where you want to use it.
此答案提供了有关保存补丁并将其应用到您想要使用它的位置的信息。
To stash the output in a file:
要将输出存储在文件中:
git stash show -p --color=never > my-patch-name.patch
Verify patch looks good:
验证补丁看起来不错:
git apply --stat my-patch-name.patch
Verify no errors:
验证没有错误:
git apply --check my-patch-name.patch
Apply the patch
应用补丁
git apply my-patch-name.patch
回答by peritus
Use
用
$> git stash list
stash@{0}: WIP on master: 84fx31c Merged with change to /public/
stash@{1}: WIP on master: 463yf85 FlupResource: also takes json as a query parameter
to get a list of your recently stashed stuff. Git actually creates commit objects when you stash.
获取您最近藏匿的东西的列表。Git 实际上会在您存储时创建提交对象。
They are commits like everything else. You can check them out in a branch:
他们像其他一切一样提交。您可以在分支中查看它们:
$> git checkout -b with_stash stash@{0}
You can then publish this branch and you colleague can merge or cherry-pick that commit.
然后你可以发布这个分支,你的同事可以合并或挑选那个提交。
回答by Davide Guerri
Above solutions won't work for binary data. The following add support for it:
上述解决方案不适用于二进制数据。以下添加对它的支持:
git stash show stash@{0} -p --binary
Edit
编辑
Note: I just wanted to add a comment to above replies but my reputation is not sufficient.
注意:我只是想对上述回复添加评论,但我的声誉还不够。
回答by stucash
I believe this might be one of the udpates from Git recently. you don't have to patch the changes you stashed away any more. you can just apply your stashed changes on one branch to another.
我相信这可能是最近来自 Git 的更新之一。您不必再修补您隐藏的更改。您可以将一个分支上的隐藏更改应用到另一个分支。
say on branch A you have stashed away some changes, referred as stash@{1}.
假设在分支 A 上您已经隐藏了一些更改,称为 stash@{1}。
you now switch to branch B. you can just do:
你现在切换到分支 B. 你可以这样做:
$git stash apply stash@{1}
this applies your branch A changes onto branch B.
这将您的分支 A 更改应用于分支 B。