Donut5
Donut5

Reputation: 15

I have code that I often use with Git, what is its equivalent in helixcore/perforce?

Okay, so I often use this code: git reset --soft HEAD~1

To undo a bad commit on SourceTree. I'm tasked to work with P4V which I don't have as much experience with, but this has always been the 'magic' for me. What is the equivalent of this in Perforce/HelixCore?

I appreciate any and all help!

Upvotes: 1

Views: 66

Answers (1)

Samwise
Samwise

Reputation: 71562

Perforce doesn't have an exact equivalent of a lot of git commands; anything that involves changing HEAD in git won't have a direct equivalent in Perforce because in Perforce you only ever submit new revisions on top of old ones (this isn't strictly true if you have admin permissions, but Perforce's core end-user workflows are built around the promise that anything you submit is immutable, and violating that promise via admin-only commands like p4 unsubmit and p4 obliterate will cause a lot of things to work poorly unless you're very careful).

If you want to undo the latest change, what you probably want to do is use the undo command. You first need to identify the specific change you want to undo, which in this case sounds like it's the latest one:

p4 changes -m1 ...

I'm using ... to limit it to submitted changes affecting the current directory; you can also specify a totally arbitrary path and/or add additional filters like --me. Once you've identified the specific change you want to undo, you can undo it just like this:

p4 undo @CHANGE

This is a lot more similar to git's revert command (which bears no resemblance at all to p4 revert, so don't confuse them) than to reset, but is probably the best path to what you're trying to do. After you run p4 undo, the files are open in your workspace with the inverse of whatever changes happened in changelist CHANGE; you can p4 submit those files to actually undo the previously submitted change in the depot, or you can make further modifications to them, maybe to selectively undo some changes while keeping others.

Upvotes: 3

Related Questions