A local stash for subversion
I recently posted a series of helper-scripts I keep in my local ~/bin for branching and merging in subversion. After noticing the large volume of patches I keep floating around in working copies, I decided to also create a stash system akin to that in git. Git's stash feature allows users to stage uncommitted change-sets into their working copy, without pushing them up-stream or integrating them into the revision history. I use this behavior frequently to pause what I am doing, do something else, and come back to what I was doing. Or to pause what I am doing, switch branches, and review someone else's incoming change-set. The commands for my svn stash are very similar to git. Quickly stash change-sets sit in a LIFO queue, and are named with uuidgen if you do not name them explicitly.
I've integrated this into my wrapper so svn help stash emits basic usage information for the command set.
scott@optimusprime:~/code/leapfrog/inmon> svn help stash
Usage: svn stash <command> [ <name> ]
list - Display all stashed changesets.
show - View the change-set patch.
save - Save a new changeset.
apply - Apply a changeset from the stash.
delete - Delete a changeset from the stash.
pop - Apply a changeset from the stash, and delete it.
help - This message
Listing stashes
The svn stash list command lists stashes that have been queued. This is simply for managing the stashes.
scott@optimusprime:~/code/leapfrog/inmon> svn stash list 482 2010-08-02 15:53 0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b 86851 2010-08-02 15:33 3f5d08c9-b9be-428d-9fb7-55dfa904e670 16756 2010-08-03 11:25 6dfd3d16-65a6-4be5-abb2-8c32d4eea4d9
Inspecting stashed changesets
Stashed change-sets can be inspected using svn stash show <stash>.
scott@optimusprime:~/code/leapfrog/inmon> svn stash show 0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b
Index: pom.xml
===================================================================
--- pom.xml (revision 5272)
+++ pom.xml (working copy)
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.leapfrog.inmon</groupId>
Applying stashes
Stashes can be applied using either svn stash apply, or svn stash pop. stash apply applies a stash without removing it. stash pop applies a stash and removes it, respectively. If no stash is specified with pop, the latest stash is the one applied. A summary of the changes made is displayed (assuming application goes as expected and there are no conflicts).
scott@optimusprime:~/code/leapfrog/inmon> svn stash apply 0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b Unstaging stash "0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b". M pom.xml scott@optimusprime:~/code/leapfrog/inmon> svn revert -R . Reverted 'pom.xml'
scott@optimusprime:~/code/leapfrog/inmon> svn stash pop Unstaging stash "6dfd3d16-65a6-4be5-abb2-8c32d4eea4d9". M services/src/main/java/com/leapfrog/inmon/services/game/play/GamePlayEventHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/etl/PointsConversionETLProcessHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/GameMetaDataAccessFacade.java M services/src/main/java/com/leapfrog/inmon/services/points/bank/MyfrogPointsBankClient.java Stash "6dfd3d16-65a6-4be5-abb2-8c32d4eea4d9" removed.
Since pop removes the stash, it will no longer appear in the list.
scott@optimusprime:~/code/leapfrog/inmon> svn stash list 482 2010-08-02 15:53 0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b 86851 2010-08-02 15:33 3f5d08c9-b9be-428d-9fb7-55dfa904e670
It can be re-staged using svn stash, or otherwise just used, since the changes are currently applied to the active working-copy.
scott@optimusprime:~/code/leapfrog/inmon> svn status ? queue.mem M services/src/main/java/com/leapfrog/inmon/services/game/play/GamePlayEventHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/etl/PointsConversionETLProcessHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/GameMetaDataAccessFacade.java M services/src/main/java/com/leapfrog/inmon/services/points/bank/MyfrogPointsBankClient.java
Cleaning up stashes
Removing stashes is fairly straight forward, svn stash delete (remove and rm are aliases for this command) removes a stash without applying it. From that point on the change-set is in the bit-bucket and cannot be retrieved.
scott@optimusprime:~/code/leapfrog/inmon> svn stash delete 0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b Stash "0a95b587-bdbd-4c70-8ca4-9d9c2ed02c5b" removed. scott@optimusprime:~/code/leapfrog/inmon> svn stash list 86851 2010-08-02 15:33 3f5d08c9-b9be-428d-9fb7-55dfa904e670
Creating stashes
Simply svn stash creates an anonymous stash from the current working-copy changes. If a label is preferred so the stash can be identified later, then svn stash save <label> will do this for you. Further interactions require using this label. It must be a single command line argument, so quotes are required if the label contains spaces.
scott@optimusprime:~/code/leapfrog/inmon> svn stash save "Point Conversion ETL changes" Changes stashed as: "Point Conversion ETL changes" Working copy reverted to 5272 scott@optimusprime:~/code/leapfrog/inmon> svn stash pop "Point Conversion ETL changes" Unstaging stash "Point Conversion ETL changes". M services/src/main/java/com/leapfrog/inmon/services/game/play/GamePlayEventHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/etl/PointsConversionETLProcessHandler.java M services/src/main/java/com/leapfrog/inmon/services/game/play/GameMetaDataAccessFacade.java M services/src/main/java/com/leapfrog/inmon/services/points/bank/MyfrogPointsBankClient.java Stash "Point Conversion ETL changes" removed.
I found this much easier to deal with than manually juggling patches, although it only automates the same process. It also gracefully handles newly added and deleted files in stashes, without leaving relic artifacts in un-staged change-sets.
I've found this useful, hopefully you will as well.
rss
Comments
No comments.