How to backup git stash content?

  • I have a work in progress
  • I need to switch to another branch to do urgent work.
  • Since my current work is not completed, I do not want to fix it. I use git stash to put this off.

In addition, I would like to backup this stash content to a shared drive. Just for safety. What is an elegant solution for archiving stash content in a file?

+5
source share
3 answers

You can get diff by running the show command:

 git stash show -p > stash.diff 

This is a diff file that you can use as a backup.

Later, you can apply diff to an existing repository:

 git apply stash.diff # and potentially stash again: git stash 
+9
source

I do not want to commit it

In fact, git stash works by making two attempts (sometimes) three, so if you hid your work, you did it, perhaps without even knowing it. But in most cases there is nothing to do with temporary fixation. Just add the current job and then do a temporary commit with:

 git commit -m 'WIP' 

Then you can push your branch to the repository, and this should be backup. When you return to finish the job, you can change this temporary commit with:

 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 can be transferred to other users, then you can direct your temporary-committed branch to another location as a backup, for example.

 git push origin local_branch:some_other_location 
+5
source

Like Tim Biegeleisen , git stash actually creates a commit - it just doesn't move any of your branches around.

You can access the last hidden content via stash@ {0} (the second to extend to stash@ {1} etc. git stash list to see the full list of what you can get).

The easiest way I can see to make stash more persistent is to create a new branch:

 $ git branch wip/adding/new/feature stash@ {0} 

Now, when the branch pointing to it, this hidden content does not expire, it will be transferred when cloning or extracting from this repo, etc.

The easiest way to backup a repo is to clone it:

 $ cd path/to/external/drive $ git clone my/repo # you can then update your backup by running : $ git fetch # from the clone 

this will save all branches and tags defined in the original repo.

+2
source

Source: https://habr.com/ru/post/1264483/


All Articles