无需还原文件即可更新SVN cmd

时间:2018-10-23 10:23:16

标签: windows batch-file svn

我有一个Windows批处理,它将定期运行以从SVN添加/删除文件

我希望脚本这样做:

  1. 删除在Windows(不是SVN)中已从SVN删除的所有文件
  2. 添加尚未受版本控制的所有文件(*.*
  3. 提交所有更改
  4. 更新文件夹,以确保该文件夹是最新的。

我有以下批次:

:: Go to my folder (already checked out as SVN folder)
cd C:\MyFolder\

:: Delete/Remove all missing files
svn status || ? { $_ -match '^!\s+(.*)' } | % { svn rm $Matches[1] }

:: Add new files
svn add *.*

:: Commit all changes
svn commit *.* -m ^"Committed on %date% %time%"

:: Update the folder
svn up --accept mine-full

我自己在Windows资源管理器中删除了文件new file.txt后会发生什么情况

  1. 运行delete命令,然后列出类似! new file.txt的文件
  2. 运行add命令,该命令会添加所有新文件(如果有的话)
  3. 提交
  4. 更新然后还原文件new file.txt <-我不希望它还原已删除的文件。

对于删除/删除部分,我还尝试了以下两个命令:

svn status || grep "^\!" || sed 's/^\! *//g' || xargs svn rm
svn status || grep "^\!" | sed 's/^\! *//g' | gawk '{print "\""$0"\"" }' | xargs svn rm  ::includes whitespaces in filenames

输出:

C:\MyFolder>svn status   || ? { $_ -match '!\s+(.*)' }   | { svn rm $Matches[1] }
!       new file.txt

C:\MyFolder>svn add *.*
svn: Skipping argument: E200025: '.svn' ends in a reserved name
svn: warning: W150002: 'C:\MyFolder\old.txt' is already under 
version control
svn: E200009: Could not add all targets because some targets are already 
versioned
svn: E200009: Illegal target for the requested operation

C:\MyFolder>svn commit *.* -m "Committed on 2018-10-23 12:15:57.90"
svn: Skipping argument: E200025: '.svn' ends in a reserved name

C:\MyFolder>svn up --accept mine-full
Updating '.':
Restored 'new file.txt'
At revision 21.
Press any key to continue . . .

最开始,该文件夹必须同步到SVN(备份),因此,如果有添加/删除的文件,也必须在SVN中添加/删除该文件

2 个答案:

答案 0 :(得分:1)

最后让它自己工作。感谢https://stackoverflow.com/a/23944546/1876355

中的@ user3689460

我已添加svn delete "missing.list",否则它已将missing.list文件添加到SVN

这是我最后的批处理脚本,可以正常工作:

:: Go to my folder (already checked out as SVN folder)
cd C:\MyFolder\

:: Delete/Remove all missing files
svn status | findstr /R "^!" > missing.list
for /F "tokens=* delims=! " %%A in (missing.list) do (svn delete "%%A")
del missing.list 2>NUL
svn delete "missing.list"

:: Commit Deletion of missing files
svn commit -m "Deleted files from MyFolder on %date% %time%"

:: Add new files
svn add *.*

:: Commit all changes and additions
svn commit *.* -m ^"Committed MyFolder on %date% %time%"

:: Update the folder
svn up --accept mine-full

答案 1 :(得分:0)

也许您可以像这样使用“ cut”来执行删除部分(从上一个输出的第9列开始取走所有内容):

svn status | grep "^\!" | cut -c 9- | xargs svn rm