Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to backup git stash content?

Tags:

  • I have pending uncommitted works
  • I need to switch to another branch for some urgent work
  • As my current Work in Progress is not finished, I don't want to commit it. I use git stash to put it aside.

Additionally, I would like to backup that stash content on a shared drive. Just for safety. What is an elegant solution to archive the stash content on file?

like image 729
Polymerase Avatar asked Feb 21 '17 04:02

Polymerase


People also ask

How do I get my data back from git stash?

Retrieve Stashed Changes To retrieve changes out of the stash and apply them to the current branch you're on, you have two options: git stash apply STASH-NAME applies the changes and leaves a copy in the stash. git stash pop STASH-NAME applies the changes and removes the files from the stash.

Where does git stash save files?

All are stored in . git/refs/stash . git stash saves stashes indefinitely, and all of them are listed by git stash list . Please note that dropping or clearing the stash will remove it from the stash list, but you might still have unpruned nodes with the right data lying around.

Can you share git stash?

You can create stash as patch file from one machine,then can share that patch file to another machines. 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.


2 Answers

You can get the diff by running show command:

git stash show -p > stash.diff 

This is the diff file which you can use as a backup.

Later you can apply the diff to the existing repository:

git apply stash.diff # and potentially stash again: git stash 
like image 122
Zbynek Vyskovsky - kvr000 Avatar answered Oct 09 '22 20:10

Zbynek Vyskovsky - kvr000


I don't want to commit it

Actually, git stash operates by making two commits (sometimes) three, so if you stashed your work, you committed perhaps without even knowing it. But there is nothing wrong most of the time with making a temporary commit. Just add your current work, and then make a temporary commit via:

git commit -m 'WIP' 

Then, you can push your branch out to the repository, and that should serve as a backup. When you return to finish the work, you can amend that temporary commit via:

git commit --amend 

Feel free to change the message to something more meaningful, but in any case the WIP message can serve as a reminder.

If the branch you are working on could be shared by others, then you could push your branch with the temporary commit to a different location as a backup, e.g.

git push origin local_branch:some_other_location 
like image 31
Tim Biegeleisen Avatar answered Oct 09 '22 20:10

Tim Biegeleisen