Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a patch from stash [duplicate]

Tags:

git

I need a way to export a stashed change to another computer.

On computer 1 I did

$ git stash save feature

I'm trying to get the stash patch to a file and then import it to another computer

$ git stash show -p > patch

This command gives me a file that I can move to another computer where this repo is cloned, but the question is how to import it as a stash again.

like image 267
Marcelo A Avatar asked Nov 23 '22 12:11

Marcelo A


2 Answers

You can apply a patch file (without committing the changes yet) by simply running

git apply patchfile

Then you can simply create a new stash from the current working directory:

git stash
like image 147
poke Avatar answered Nov 26 '22 02:11

poke


You can create stash as patch file from one machine,then can share that patch file to another machines.

Creating the stash as a patch

$ git stash show "stash@{0}" -p > changes.patch

The “stash@{0}” is the ref of the stash.It will create patch file with latest stash. If you want different one use command $ git stash list to see your list of stashes and select which one you want to patch.

Applying the patch

Now transfer that stash to another machine and paste it into the root folder of your project. Then run this command

$ git apply changes.patch

If there is mistake and you want to reverse the change

$ git apply changes.patch --reverse
like image 32
Simran Avatar answered Nov 26 '22 01:11

Simran