5

In Perforce, how do I revert changes I have made a file?

$ p4 status
UI\FormMain.cs - reconcile to edit //UI/FormMain.cs#73

$ p4 revert UI/FormMain.cs
UI/FormMain.cs - file(s) not opened on this client.

In Git I do this with the command git checkout or git restore.

$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Form.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

$ git checkout Form.cs

$ git status
# On branch master
nothing to commit, working directory clean
2
  • The usual Perforce workflow is to explicitly open files for edit first via p4 edit before touching the files (otherwise the server won't know and won't do anything when you try p4 revert). If you follow that practice, things will go more smoothly.
    – jamesdlin
    Commented Jan 7, 2013 at 17:11
  • Are people actually still using Perforce? Commented Jan 9 at 14:32

2 Answers 2

7

If the file isn't opened, yet you have made changes to it locally, use

p4 sync -f UI/FormMain.cs

to tell Perforce to forcibly (-f) sync the copy of FormMain.cs that you have on your machine with the version from the server.

0
0

Instead of p4 revert UI/FormMain.cs you should call p4 revert //UI/FormMain.cs since that's the absolute path in depot notation. The file with out the leading // marks a file relative to your current location in the client workspace.

3
  • This doesn't work, it gives me the same 'file(s) not opened on this client.' error. Commented Jan 7, 2013 at 14:43
  • what does "p4 opened" tell you?
    – pitseeker
    Commented Jan 7, 2013 at 14:52
  • 1
    p4 revert <file> works only for files opened for edit with p4 edit <file> or via checkout operation in P4V application
    – N0dGrand87
    Commented Feb 25, 2016 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.