Perforce fast sync a directory to a clean state

◇◆丶佛笑我妖孽 提交于 2019-12-05 03:44:09

Perforce has added a new command "p4 clean" in 2014.1 that does exactly what you are looking for, by resetting your workspace to its #have state:

  • New files not in Perforce will be deleted
  • Files modified outside of Perforce control will be reset
  • Files deleted outside of Perforce control will be restored

The command is an alias for "p4 reconcile -w" and uses the hashsum of the files to determine their state in your workspace.

Another Unix/Linux snippet that should remove all files that have never been tracked by perforce:

find . -type f | p4 -x- files 2>&1 | sed -n -e 's/ - no such file(s).//p' | xargs -d '\n' rm

If you have Unix/Linux this may work.

In Perforce you can "Reconcile Offline Work" through p4v, as seen here or through the command line as seen here. You already do the latter as covered in your question, as you revert the edited and deleted files. Added files are trickier. The second link would have you do the following.

find . -type f -print | p4 -x - add
find . -type l -print | p4 -x - add

to add files and symlinks in Unix

The tricky part is physically removing the files you've added. This isn't pretty, but I think it would work. p4 opened | grep add | cut -f1 -d"#" | p4 -x- where | cut -f3 -d" "

Then you need to do a

p4 revert directory/...

or do something similar to that above when removing files.

I needed this for a build server with svn. What I did in the end was:

  • Update the workspace
  • Delete the old “build folder” if there is one
  • Xcopy the workspace to the “build folder”
  • Do the build in the “build folder”

That way I knew there was nothing for an old build hanging about.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!