linux svn revert,svn revert 复原整个目录

参考下面两个问答:

http://stackoverflow.com/questions/8139605/does-svn-have-a-revert-all-command

-----------------------------------

You could do:

svn revert -R .

This will not delete any new file not under version control. But you can easily write a shell script to do that like:

for file in `svn status|grep "^ *?"|sed -e 's/^ *? *//'`; do rm $file ; done

-----------------------------------

There is a command

svn revert -R .

In addition

If you want to revert a whole directory of files,you can use the --depth=infinity option:

svn revert --depth=infinity

svn revert is inherently dangerous, since its entire purpose is to throw away data—namely, your uncommitted changes. Once you've reverted, Subversion provides no way to get back those uncommitted changes

-----------------------------------

http://stackoverflow.com/questions/1239998/how-can-i-remove-all-my-changes-in-my-svn-working-directory

-----------------------------------

Used a combination of other peoples answers to come up with this solution

revert normal local svn changes

svn revert -R .

remove any other change and supports removing files/folders with spaces, etc.

svn status --no-ignore | grep -E '(^\?)|(^\I)' | sed -e 's/^. *//' | sed -e 's/\(.*\)/"\1"/' | xargs rm -rf

don't forget to get the latest files from svn

svn update --force

-----------------------------------

None of the answers here were quite what I wanted. Here's what I came up with:

# Recursively revert any locally-changed files

svn revert -R .

# Delete any other files in the sandbox (including ignored files),

# being careful to handle files with spaces in the name

svn status --no-ignore | grep '^\?' | \

perl -ne 'print "$1\n" if $_ =~ /^\S+\s+(.*)$/' | \

tr '\n' '\0' | xargs -0 rm -rf

Tested on Linux; may work in Cygwin, but relies on (I believe) a GNU-specific extension which allows xargs to split based on '\0' instead of whitespace.

The advantage to the above command is that it does not require any network activity to reset the sandbox. You get exactly what you had before, and you lose all your changes. (disclaimer before someone blames me for this code destroying their work) ;-)

I use this script on a continuous integration system where I want to make sure a clean build is performed after running some tests.

Edit: I'm not sure this works with all versions of Subversion. It's not clear if the svn status command is always formatted consistently. Use at your own risk, as with any command that uses such a blanket rm command.

-----------------------------------

svn status | grep '^M' | sed -e 's/^.//' | xargs rm

svn update

Will remove any file which has been modified. I seem to remember having trouble with revert when files and directories may have been added.

-----------------------------------

-----------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值