16

I've dug through the interwebs all I can, and I can't for the lack of me find any way of easily stashing or branching locally with perforce. I know of the git wrapper for perforce, but it really doesn't seem too well developed or reliable from everything I've read about it.

bergyman
  • 4,480
  • 3
  • 23
  • 32

3 Answers3

37

Perforce 2009.2 has shelve and unshelve, that let you put modifications on the server, without checking them in. http://blog.perforce.com/blog/?p=1872

I think that provides the sort of functionality you want?

If you aren't yet using 2009.2, there are also P4_Shelve and p4tar as possible alternatives.

Douglas Leeder
  • 52,368
  • 9
  • 94
  • 137
  • 3
    Too bad the OP didn't check this question more than 4 hours after that answer above, it's a shame that it's the chosen answer. – umassthrower Aug 19 '13 at 19:40
4

Regarding branching, I doubt you can "branch" locally in Perforce, nor could you natively stash.

  • Git is based on a graph of commits (a DAG - Directed Acyclic Graph actually), which will display only the content of a commit (trees and blobs)
  • Perforce is a linear VCS, based on composition of selection rules (it will compose what to display based on local selection rules)

Regarding branching:

  • A branch in Git is just a light-weight and local alias to a head[*] / tip commit.
  • A branch in Perforce is:
    • a codeline (most likely meaning when used as a noun)
    • a branch view specification (as in the entity created by "p4 branch" command - also a noun) - these are talked about below
    • when used as a verb ("to branch") it means to use the "p4 integrate" command to create a new codeline (or branch!) of one or more files

As mentioned in this introduction to perforce branching, Perforce, being heavily linked to its central depo, need to create the relevant metadata for each files to create a branch.
Git would only write some bits to register the creation of a new branch!

[*] git branches are stored in the .git/refs/heads/ subdirectory

MarcH
  • 18,738
  • 1
  • 30
  • 25
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 25
    Sigh. I'm really starting to detest Perforce. Why do people pay for this? – bergyman Jan 20 '10 at 20:53
  • @Chris: Well... http://stackoverflow.com/questions/1444427/commercial-version-control/1444454#1444454 or http://stackoverflow.com/questions/1346031/is-perforce-worth-it/1346196#1346196 – VonC Jan 20 '10 at 21:19
  • 6
    Perforce seems to be lacking many of the, what I've come to recognize as almost essential at least to myself, workflows. I've used cvs, svn, git and now Perforce. Hands down git made the most sense to me. Now with perforce, if I'm in the middle of a bug fix and something else comes along, there seems to be little I can do aside from manually shifting around files in the changelists to make sure I'm not checking in unfinished, unrelated work to whatever has just popped up that requires my attention. Locally stashing or branching make this cake Am I missing some asy way to do this with Perforce? – bergyman Jan 20 '10 at 21:27
  • @Chris: in a composition-based system for version selection (akin to the ClearCase system, as I detail it in http://stackoverflow.com/questions/763099/flexible-vs-static-branching-git-vs-clearcase-accurev/764219#764219), what you need to do "when unrelated work" pops up, is to leave your current work untouched, and create *another* Perforce view or workspace, with the right configuration, in order to address that unrelated work. – VonC Jan 20 '10 at 21:43
  • 4
    perforce is totally awful and the worst piece of *#^( i've ever been forced to use. – Kevin Depue Jul 17 '14 at 20:49
2

A future version of Perforce will have private local branching. P4Sandbox will allow you to have a local, disconnected subset of the depot. You can pull from the central server, do whatever you want in your sandbox (including branching and integrating) and then, if you wish, push back to the central server.

Shelving is the closest equivalent of git stash, as explained in Douglas Leeder's answer.

(Although it initially appeared that P4Sandbox would make its debut in version 2011.1, the 2011.1 beta does not have the feature, nor can I find any mention of it in the documentation for that version. As of August 2011, the P4Sandbox beta was slated for "this fall".)

daxelrod
  • 2,499
  • 1
  • 22
  • 30
  • 2
    The P4ASandbox link above is 404. – Daryl Spitzer Dec 19 '14 at 17:59
  • 1
    It looks like P4Sandbox was released in 2012.3. See http://www.perforce.com/perforce/doc.current/user/p4sandboxnotes.txt. See also http://www.perforce.com/product/components/server-clients/distributed-version-control and http://www.perforce.com/perforce/doc.current/manuals/p4sandbox/index.html. – Daryl Spitzer Dec 19 '14 at 18:10
  • 1
    @Daryl All links in answer and comments are no longer valid. – Samuel Jun 17 '16 at 17:05