Search code examples
gitbranchperforceshelvep4v

Perforce equivalent of git local commit


I just started using Perforce after using Git for a year. Is there any equivalent of a git local commit to my branch in perforce.

Essentially, if I want to work on a complex task which might need undoing and redoing of my specific changes, is there any way to accomplish this in Perforce? The way I would do it in Git would be committing my changes to a branch and having several commits within the branch before merging in to master.


Solution

  • I think p4 shelve might be useful to you here.

    Longer answer:

    The way p4 works is that you have to unlock a file using p4 edit, or add a new file using p4 add. This will create a changelist that basically has all the files that are staged for your next commit.

    p4 submit can then be used to push (in git terminology) all the changes in your changelist to the repository/depot.

    Now if you don't want to submit right away, you can shelve those changes using p4 shelve. This will create a local checkpoint of your changelist which you can go back to, or undo. You may also create multiple shelved copies building one after the other. You can probably replicate all the functions of a git commit with this command.

    See the p4 shelve command reference for more details.