我想提交一个不同的审查,为一个开源项目。

我得到的代码使用SVN(从终端,Ubuntu)。我对一些文件做了小修改。现在我只想提交一个更改。我所做的其余更改是用于调试的,不再需要。

我已经使用svn di > ~/os/firstdiff.diff生成了diff

所以我的问题是,如何丢弃局部更改?

是否有SVN的方法来做到这一点?如果没有,我将不得不去每个文件,并删除我所有的编辑。 然后我会生成一个新的diff,并提交它。


只需使用svn revert命令,例如:

svn revert some_file.php

它(和其他svn命令一样)在svnbook资源或手册页,甚至svn help命令中都有很好的文档。


你可以用

 svn diff important/file1.c important/file2.c > $HOME/os/firstdiff.diff

在发表你的不同意见时,别忘了告诉你所反对的修订意见。

正如其他人回答的那样,您也可以小心地使用svn revert。这取决于你是否想为将来的工作保留你的本地更改。


您可以对要放置的文件使用commit命令,并使用svn revert命令丢弃剩余的本地更改


需要使用svn revert命令恢复所有修改。

将更改恢复到文件:svn Revert foo.c 恢复文件的整个目录:svn Revert——recursive。


丢弃一个特定文件中的本地更改:

$ svn revert example_directory/example_file.txt

丢弃某个特定文件夹中的本地更改:

$ svn revert -R example_directory/

简单的svn恢复是足够的原始海报。但是,简单的svn还原在更一般的情况下是不行的

将你想要共享的编辑和不想共享的编辑都放在同一个文件中, 为了自己的个人利益,保留一些你仍然感兴趣的地方变化。

@ErichBSchulz建议使用git add -p是非常合理的,在这种情况下更普遍适用。答案只是缺乏一些细节。假设你的当前目录是你想要创建可共享补丁的目录,你可以这样做:

Checkout pristine version from subversion to a different directory (choose a directory name that does not exist, here using subdirectory TMP/). $ url=$(svn info . | awk '/^URL/ {print $2}') $ svn checkout "$url" TMP Using that pristine svn checkout as a basis, init a git repository, ignoring .svn directories; commit everything in svn head to your temporary git repository $ cd TMP $ git init && echo ".svn/" > .gitignore $ git add -A && git commit $ cd .. Copy the newly prepared git repository meta data to your original working directory; as the pristine subversion checkout directory is not needed, you can get rid of it. Your working directory is now both git and subversion repository: $ mv TMP/.git . $ rm -rf TMP/ You can now use powerful and convenient git add -p to interactively choose exactly what you want to share, and commit them to your git repository. If you need to add files to the commit, do also git add <file-to-add> before git commit $ git add -p <interactively select (and edit) the chunks you want to share> $ git add ${the_list_of_files_not_in_yet_in_svn_you_want_to_add} $ git commit Using the commit, prepare a patch that you want to share. For this purpose, you could also use git diff HEAD^..HEAD, or git format-patch (the latter can be used to directly prepare emails to be sent containing the patch or multiple patches): $ git show -p HEAD > my-mighty-patch.patch

要去除git元数据,只需执行rm -rf .git/。如果您计划继续使用原始工作目录,则可以继续使用git来管理本地更改。在这种情况下,您可能会从学习如何使用git svn中获益。

注意:如果你熟悉git,这是相当琐碎的事情即兴发挥。否则看起来可能有点乱。您可以根据这些步骤编写一个脚本来概括这种方法,为svn实现“交互式提交”或“交互式补丁创建”,这可以在不了解git的情况下使用。


转到该存储库的根目录并运行以下命令

svn revert --depth=infinity .

我知道这是一个老问题,但是……这现在可以很容易地完成:

svn revert -R --remove-added /path/to/dir && svn cleanup --remove-unversioned /path/to/dir

第一部分递归地恢复更改,并删除已添加但未提交的文件。

第二部分删除路径中所有未版本化或被忽略的项。

以上信息的最佳来源。就是svn客户端本身

❯ svn help revert
revert: Restore pristine working copy state (undo local changes).
usage: revert PATH...

  Revert changes in the working copy at or within PATH, and remove
  conflict markers as well, if any.

  This subcommand does not revert already committed changes.
  For information about undoing already committed changes, search
  the output of 'svn help merge' for 'undo'.

Valid options:
  --targets ARG            : pass contents of file ARG as additional args
  -R [--recursive]         : descend recursively, same as --depth=infinity
  --depth ARG              : limit operation by depth ARG ('empty', 'files',
                             'immediates', or 'infinity')
  -q [--quiet]             : print nothing, or only summary information
  --changelist [--cl] ARG  : operate only on members of changelist ARG
  --remove-added           : reverting an added item will remove it from disk

❯ svn help cleanup
cleanup: Either recover from an interrupted operation that left the working copy locked,
or remove unwanted files.
usage: 1. cleanup [WCPATH...]
       2. cleanup --remove-unversioned [WCPATH...]
          cleanup --remove-ignored [WCPATH...]
       3. cleanup --vacuum-pristines [WCPATH...]

  1. When none of the options --remove-unversioned, --remove-ignored, and
    --vacuum-pristines is specified, remove all write locks (shown as 'L' by
    the 'svn status' command) from the working copy.  Usually, this is only
    necessary if a Subversion client has crashed while using the working copy,
    leaving it in an unusable state.

    WARNING: There is no mechanism that will protect write locks still
             being used by other Subversion clients. Running this command
             without any options while another client is using the working
             copy can corrupt the working copy beyond repair!

  2. If the --remove-unversioned option or the --remove-ignored option
    is given, remove any unversioned or ignored items within WCPATH.
    Note that the 'svn status' command shows unversioned items as '?',
    and ignored items as 'I' if the --no-ignore option is given to it.

  3. If the --vacuum-pristines option is given, remove pristine copies of
    files which are stored inside the .svn directory and which are no longer
    referenced by any file in the working copy.