我想为一个开源项目提交一个差异以供审查。
我使用 SVN(来自终端,Ubuntu)获得了代码。我在几个文件中做了一些小的编辑。现在我只想提交一个更改。我所做的其余更改用于调试,不再需要。
我使用 svn di > ~/os/firstdiff.diff
生成了差异
所以我的问题是,如何丢弃我的本地更改?
有SVN的方法吗?如果没有,我将不得不去每个文件并删除我所有的编辑。然后我会生成一个新的差异,并提交它。
只需使用 svn revert
命令,例如:
svn revert some_file.php
它(与所有其他 svn 命令一样)在 svnbook resource 或手册页中,甚至在 svn help
命令中都有详细记录。
您需要使用 svn revert 命令恢复所有更改:
恢复对文件的更改:svn revert foo.c
恢复整个文件目录: svn revert --recursive 。
svn revert --recursive .
帮助了我很多。
--recursive
参数会还原任何本地更改,这就是问题所在。
要放弃一个特定文件中的本地更改:
$ svn revert example_directory/example_file.txt
要放弃一个特定文件夹中的本地更改:
$ svn revert -R example_directory/
对于原始海报来说,简单的 svn revert
就足够了。但是,一个简单的 svn revert
不会在更一般的情况下执行
在同一个文件中同时拥有您想要共享的编辑和不想共享的编辑,拥有您仍然有兴趣为自己的私人利益而保留的本地更改。
@ErichBSchulz 使用 git add -p
的建议非常合理,并且在这种情况下更普遍适用。答案只是缺少一些细节。假设您的当前目录是您要制作可共享补丁的目录,您可以执行以下操作:
将原始版本从 subversion 检出到不同的目录(选择一个不存在的目录名称,这里使用子目录 TMP/)。 $ url=$(svn info . | awk '/^URL/ {print $2}') $ svn checkout "$url" TMP 使用原始的 svn checkout 作为基础,初始化一个 git 存储库,忽略 .svn 目录;将 svn head 中的所有内容提交到您的临时 git 存储库 $ cd TMP $ git init && echo ".svn/" > .gitignore $ git add -A && git commit $ cd .. 将新准备的 git 存储库元数据复制到您的原始工作目录;由于不需要原始的 subversion checkout 目录,您可以摆脱它。您的工作目录现在是 git 和 subversion 存储库: $ mv TMP/.git 。 $ rm -rf TMP/ 您现在可以使用强大而方便的 git add -p 交互式地选择您想要共享的内容,并将它们提交到您的 git 存储库。如果您需要将文件添加到提交中,请在 git commit 之前执行 git add
要摆脱 git 元数据,只需执行 rm -rf .git/
。如果您打算继续修改原始工作目录,您可以继续使用 git
来管理您的本地更改。在这种情况下,您可能会从学习如何使用 git svn
的投资中受益。
注意:如果您熟悉 git
,那么即兴发挥这是相当简单的事情。否则这看起来可能有点乱。您可以通过从这些步骤中编写脚本来为 svn 实现“交互式提交”或“交互式补丁创建”来概括该方法,无需了解 git 即可使用。
你可以使用
svn diff important/file1.c important/file2.c > $HOME/os/firstdiff.diff
发布你的差异时,不要忘记告诉你正在比较的版本。
正如其他人回答的那样,您也可以谨慎使用 svn revert
。这取决于您是否要为将来的工作保留本地更改...
revert
更改我的更改。所以我以后会用你的方式。
转到该存储库的根目录并运行以下命令
svn revert --depth=infinity .
svn revert -R .
可能更短
我意识到这是一个旧查询,但是......现在可以轻松完成:
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.
你可以在你想放的文件上使用commit命令,并使用svn revert命令丢弃剩余的本地更改
不定期副业成功案例分享