当对存储在Subversion repo中的软件进行编程时,我经常修改一些文件,然后注意到我想对我的主要工作做一些准备性更改。例如,在实现新功能时,我注意到一些重构可能会对我有所帮助。

为了不将两个不相关的更改混合在一起,在这种情况下,我想“收起”我的更改,即恢复到存储库版本,做一些其他更改,提交这些更改,然后“取回”我的更改。

Git-stash允许这样做。有没有办法在Subversion中直接或通过一些插件或脚本来做到这一点?Eclipse插件也可以。


当前回答

我总是保持第二次签出,我称之为“trunk_clean”。每当我需要做一个与我正在做的事情相关的快速、孤立的更改时,我就在签出时提交。

其他回答

从1.10.0(2018-04-13)开始,您有实验性的svn shelve命令。(TortoiseSVN支持该命令)它只是一个保存补丁并应用回来的助手,因此它与svn diff + patch有相同的限制(即不能处理二进制文件和重命名)。(编辑:看起来下一个版本1.11.0将支持二进制文件)

编辑^2:1.11.0(发布2018-10-30)支持二进制文件。暂不支持搁置重命名的文件。1.11中的置物架与1.10中创建的置物架不兼容。

编辑^3:1.12.0(发布2019-04-24),支持复制和重命名。1.12中的货架与早期版本创建的货架不兼容。

编辑^4:1.13.0(2019年10月)和1.14.0(2020年5月)的搁置没有变化。命令仍被标记为实验性,需要定义SVN_EXPERIMENTAL_COMMANDS=shelf3才能启用该特性。看起来这个功能目前还没有分类。

设计说明可以在开发者的Wiki上找到。

$ svn x-shelve --help
x-shelve: Move local changes onto a shelf.
usage: x-shelve [--keep-local] SHELF [PATH...]

  Save the local changes in the given PATHs to a new or existing SHELF.
  Revert those changes from the WC unless '--keep-local' is given.
  The shelf's log message can be set with -m, -F, etc.

  'svn shelve --keep-local' is the same as 'svn shelf-save'.

  The kinds of change you can shelve are committable changes to files and
  properties, except the following kinds which are not yet supported:
     * copies and moves
     * mkdir and rmdir
  Uncommittable states such as conflicts, unversioned and missing cannot
  be shelved.

  To bring back shelved changes, use 'svn unshelve SHELF'.

  Shelves are currently stored under <WC>/.svn/experimental/shelves/ .
  (In Subversion 1.10, shelves were stored under <WC>/.svn/shelves/ as
  patch files. To recover a shelf created by 1.10, either use a 1.10
  client to find and unshelve it, or find the patch file and use any
  1.10 or later 'svn patch' to apply it.)

  The shelving feature is EXPERIMENTAL. This command is likely to change
  in the next release, and there is no promise of backward compatibility.

Valid options:
  -q [--quiet]             : print nothing, or only summary information
  --dry-run                : try operation but make no changes
  --keep-local             : keep path in working copy

(...)

$ svn x-unshelve --help
x-unshelve: Copy shelved changes back into the WC.
usage: x-unshelve [--drop] [SHELF [VERSION]]

  Apply the changes stored in SHELF to the working copy.
  SHELF defaults to the newest shelf.

  Apply the newest version of the shelf, by default. If VERSION is
  specified, apply that version and discard all versions newer than that.
  In any case, retain the unshelved version and versions older than that
  (unless --drop is specified).

  With --drop, delete the entire shelf (like 'svn shelf-drop') after
  successfully unshelving with no conflicts.

  The working files involved should be in a clean, unmodified state
  before using this command. To roll back to an older version of the
  shelf, first ensure any current working changes are removed, such as
  by shelving or reverting them, and then unshelve the desired version.

  Unshelve normally refuses to apply any changes if any path involved is
  already modified (or has any other abnormal status) in the WC. With
  --force, it does not check and may error out and/or produce partial or
  unexpected results.

  The shelving feature is EXPERIMENTAL. This command is likely to change
  in the next release, and there is no promise of backward compatibility.

Valid options:
  --drop                   : drop shelf after successful unshelve
(...)

$ svn help | grep x-
 x-shelf-diff
 x-shelf-drop
 x-shelf-list (x-shelves)
 x-shelf-list-by-paths
 x-shelf-log
 x-shelf-save
 x-shelve
 x-unshelve

在GPL 3下有一个名为svn-stash的小Python 2脚本:https://github.com/frankcortes/svn-stash。

它的工作原理类似于前面提到的svn diff/patch解决方案,并提供了将更改作为diffs推入和弹出到某个本地目录的功能。不幸的是,存储不能被命名,只有最后一个可以被弹出(好吧,是的,它是一个堆栈,但没有这样的限制的真正原因)。但是,您总是可以将缺少的特性构建到源代码中。

它是为*ix编写的,但是在将每个“/”替换为os之后。sep它在Windows下工作得很好。

如果您使用svn 1.7或更高版本,您需要更改is_a_current_stash():删除如果“。在os.listdir(CURRENT_DIR):,因为在1.7 WC中只有一个顶级的。svn子目录。

另一种选择是将当前签出复制到一个新目录并恢复所有更改。这样就省去了在服务器上创建临时分支的麻烦——毕竟存储是一个本地操作,不是每个人都应该看到,而且可以经常这样做。

提交修复程序后,您可以更新主工作副本并删除“存储区域”

在我的实践中,我使用git init在Subversion存储库的trunk目录中创建一个git存储库,然后添加*。git到吸盘忽略模式。

在修改了一些文件后,如果我想继续使用Subversion主线进行工作,我只需使用git stash来隐藏我的工作。在提交到Subversion存储库之后,我使用git stash pop来恢复我的修改。

由于Subversion不完全支持存储特性, 我就像这样手动操作。

将开发和生产(发布)项目放在一个分开的路径上。

source\code\MyApp         -- Development
release\MyApp(release)    -- Production(release)

你可以在开发过程中为你的项目添加任何新功能, 你只会承诺有意义的进展,或者应该为稳定释放一些东西。

当你必须将它发布到生产环境,开放生产项目,更新svn并做一些事情来发布(构建,导出…)等等)。

我知道这有点麻烦,但与开发进度相比,发布进度并不经常发生(对我来说不是这样,但我知道有些项目是这样),这种方式适合我。

由于项目组成员使用svn,所以具体项目我使用svn,所以我必须遵循。 最好的解决方案是使用git,它有完善的版本控制系统,比svn更好。