1

I accidentally edited the wrong file locally. The file is in a Perforce repo. What would be the best way to get the repo version, discarding the edited version and not changing other (edited) files?

For the question at Is there an equivalent to git stash in perforce? I see that p4 shelve could be a possibility?

Is another possibility to delete the file? And then follow Recover deleted files from Perforce with a p4 sync -f?

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43

1 Answers1

2

If the file is not open and you want to discard the edited version, either of the following will do the trick:

# Overwrite the local (unopened) file IFF it's different from the depot version
p4 clean FILE

# Overwrite the local (unopened) file no matter what.
p4 sync -f FILE

If the file is not open and you want to discard your local edits for now, but keep a copy of them (without submitting them):

# open the file for edit
p4 edit FILE

# shelve your local changes on the server for later recovery
p4 shelve FILE

# revert an opened local file to the depot version
p4 revert FILE

If the file is already open for edit and you just want to discard your local changes without shelving:

# revert an opened local file to the depot version
p4 revert FILE
Samwise
  • 68,105
  • 3
  • 30
  • 44