How can I format patch with what I stash away

岁酱吖の 提交于 2019-11-28 13:41:34

问题


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)?

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?

And how can I apply a patch in other repository?


回答1:


Sure, git stash show supports this:

git stash show -p



回答2:


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



回答3:


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.

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.




回答4:


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.




回答5:


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.

say on branch A you have stashed away some changes, referred as stash@{1}.

you now switch to branch B. you can just do:

$git stash apply stash@{1}

this applies your branch A changes onto branch B.



来源:https://stackoverflow.com/questions/2160638/how-can-i-format-patch-with-what-i-stash-away

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!