linux下使用P4(命令行)(转)

 环境变量:
export P4PASSWD=abcdefg
export P4CLIENT=dyoldfish.com    //这个是workspce
export P4USER=dyoldfish
export P4PORT=192.168.1.198:1666

 

命令:
1、p4 client  #配置本地信息,文件下载在哪里在这里面配置,Root项
2、p4 sync   #从perforce 下载文件
3、p4 login  #登陆perforce 
4、p4 help   #显示关于命令的帮助
5、p4 -h     #显示关于p4的帮助
6、 p4  labels  ...   #显示和这个目录相关的标签 
7、p4 sync @dyoldfish_label #同步标签dyoldfish_label中的所有文件
8、p4 files @dyoldfish_label  #查看标签dyoldfish_label所包含的文件列表
9、p4 revert     #回复所有打开的文件
10、p4 revert -n ... #回复所有打开却没提交的文件
11、p4 branch dyoldfish_brach   #新建分支
12、p4 integrate -b   dyoldfish_brach   #合并分支dyoldfish_brach中描述的文件
13、p4 opened  #查看打开的文件
14、p4 help commands  #查看p4所有命令的帮助
15、p4  dirs  -H .   #显示当前目录
16、p4 branches    #显示所有的分支 
17、 p4 delete  filename   #从p4删除文件 
18、p4 changelists -L ...   #显示当前目录下面所有文件的修改注释
19、p4 label dyoldfish_label   #新建标签 dyoldfish_label,编辑标签
20、p4 tag -l dyoldfish_label ... #把当前目录下面的所有文件添加到标签 dyoldfish_label
21、p4 changes ...   #当前目录的changelist
22、 p4 sync @10931     #sync file @changelist
23、 p4 sync ...@10929  #only sync  localfile@changelist
24、p4 help revisions    #查看关于文件范围的帮助

25、p4 edit filename  对文件进行编辑,相当于图形界面中的check out

 

所以我们经常用到就是同步 p4 sync

编辑, p4 edit;然后提交 p4 submit -d "description" filename or dir;当然在提交之前最好看一下哪些文件被check out了,以免误操作,我们可以用p4 opened.

 

p4 unshelve -s 323071是把别人shelve上去的文件弄下来,但不会check out

 

 

 

export好变量之后,然后用1进行配置,就可以用p4 sync进行代码下载了 如p4 sync //depot/proj1/...@21

./p4 sync //XMS/SS7_Mainline/HMCallAnalyzer/java/com/empirix/hm/realtime/commandbar/...(目录)

./p4 sync //XMS/SS7_Mainline/HMCallAnalyzer/java/com/empirix/hm/realtime/commandbar(文件)

如果commandbar是目录则后面要加上/...,如果是文件的话就不用

 

 

 

在虚拟机上使用p4

 

一共分为如下几步:

1.     要在Linux上用P4,就需要虚拟机能够访问外网

2.     安装及配置P4

3.     配置源代码环境

 

下面具体介绍一下各个步骤:(我称我们的工作机本身为“主机”)

1.     配置虚拟机访问外部网络。设置步骤如下

1)共享主机网卡

本地连接 -》 属性 -》高级 -》选择允许其它网络通过本...,并选择家庭网络连接为 VMware Network Adapter VMnet1

 

2)设置虚拟机IP信息

选择Traditional ….

 

3)设置静态IP

IP     192.168.0. xxx

Subnet mask 255.255.255.0

DNS        192.168.0.1(编辑/etc/reslove.conf)

Default Gateway  192.168.0.1

2.     安装及配置P4

1)     下载客户端http://www.perforce.com/perforce/downloads/index.html 我使用的是The Perforce Command-Line Client (P4)

2)     把客户端放在文件夹 /usr/local/bin 。这样能在任何目录直接使用p4命令

3)     配置客户端,在线帮助有很多种方式,我使用配置文件方式。步骤如下

a.     在/usr下面新建一个文件夹p4config (可以自定义),在文件夹里面新建文件p4.configfile.

b.     用VI打卡p4.configfile,输入如下配置

 

P4CLIENT=(定义你的工作空间,比如ygxu_xms)

P4PASSWD=(你的密码)

P4PORT=10.12.33.133:1700

P4USER=(你的用户名)

 

保存退出。

c.      配置环境变量。修改后需要重启这个才生效

用vi打开 /etc/profile,末尾处加入

 

#

# pv4 config file path

#

if test -z "$P4CONFIG" ; then

        export P4CONFIG=/usr/p4config/p4.configfile

fi

 

d.     测试环境配置是否成功

命令 p4 info,如果显示了连接信息,则OK,否则会提示连接不上

 

3.     配置源代码环境

使用命令 p4 client会有如下信息显示

 

Client:  你上面配置的工作空间

Update: 2010/01/19 20:38:36

Access: 2010/01/21 02:57:38

Owner:   你的用户名

Host:   linux

Description:

        Created by ygxu.

Root:   /home/hammer

Options:        noallwrite noclobber nocompress unlocked nomodtime normdir

SubmitOptions:  submitunchanged

LineEnd:        local

View:

       ….

        //XMS/SS7_Mainline/... //Arthur_Xms/XMS/SS7_Mainline/...

       ….

 

两个地方需要修改:

a . Root .这个决定你的代码会放在什么地方,如上,我的是/home/hammer

b. View.这个决定你需要取哪些代码下来,因为一般不会把全部代码取下来,在Linux上我们一般只需要XMS的SS7_Mainline,所以把其他的删掉,修改成上面这个样子

      

      注意事项,一定要保证空间足够,建议先删掉原来的SS7_Mainline,使用Shrink工具回收空间之后再取代码。

      好了,使用p4 sync命令吧,就可以继续工作了!

      关于p4的使用命令,文档如下:

http://www.perforce.com/perforce/technical.html

 

更详细的命令格式参考 http://www.perforce.com/perforce/doc.current/manuals/cmdref/index.html

p4客户端下载 http://www.perforce.com/perforce/downloads/index.html

 

本文转自http://blog.csdn.net/dyoldfish/archive/2007/08/28/1761940.aspx

from: http://blog.csdn.net/wind19/article/details/4890190

 

 

--------------------------

How to Setup p4 in Linux / Unix

software configuration management tools

 

How to Setup p4 in Linux / Unix
Well many people have these questions to me that they are facing issues setting up p4 client in Linux or Unix. The Solution is pretty much straight forwards but sometimes we miss some of things which delay the setup process. 
Here I have tried to points out these already available on Perforce Knowledge base site.
Download and Installations:


1.

Download the p4 executable file from the Perforce web site:

http://www.perforce.com/perforce/downloads/index.html 
The Perforce client programs are typically downloaded to /usr/local/bin.


2.

Make the p4 file executable (chmod +x p4)

Perforce Configuration and Workspace Setting
Method 1
Using Config Files:
Config files are text files containing Perforce settings that are in effect for files in and below the directory where the config file resides. Config files are useful if you have multiple client workspaces on the same machine. By specifying the settings in config files, you avoid the inconvenience of changing system settings every time you want to work with a different workspace.
To use config files, you define the P4CONFIG environment variable, specifying a file name (for example, .p4config). When you issue a command, Perforce searches the current working directory and its parent directories for the specified file and uses the settings it contains (unless the settings are overridden by command-line flags).
P4CONFIG = .p4config 
Each setting in the file must be specified on its own line, using the following format: 
setting=value

The following settings can be specified in a config file.


Setting

Description

P4CLIENT

Name of the current client workspace.

P4EDITOR

The editor invoked by those Perforce commands that use forms.

P4HOST

Hostname of the client workstation. Only useful if the Host: field of the current client workspace has been set in the p4 client form.

P4PASSWD

Supplies the current Perforce user's password for any Perforce client command.

P4PORT

The host and port number of the Perforce server or proxy with which to communicate.

P4USER

Current Perforce user name.

For details about these settings, refer to the Perforce Command Reference.

Example: Using config files to handle switching between two workspaces
Ona switches between two workspaces on the same machine. The first workspace is ona-ash. It has a client root of /tmp/user/ona and connects to the Perforce server at ida:1818. The second workspace is called ona-agave. Its client root is /home/ona/p4-ona, and it uses the Perforce server at warhol:1666.

Rama sets the P4CONFIG environment variable to .p4config. She creates a file called .p4config in /tmp/user/rama containing the following text: 
P4PORT=ida:1818
P4CLIENT=ona-ash

She creates a second .p4config file in/home/rama/p4-ona. It contains the following text:
P4PORT=warhol:1666
P4CLIENT=ona-agave

Any work she does on files under /tmp/user/rama is managed by the Perforce server at ida:1818 and work she does on files under /home/rama/p4-ona is managed by the Perforce server at warhol:1666.

Method 2: Environment Variable Setting

To configure server connection settings using environment variables, set P4PORT to host:port, as in the following examples.

If the server is running on

and is listening to port

set P4PORT to

your computer

1666

localhost:1666

perforce

1666

1666

Example:
export P4PORT=X.X.X.X\:1667
export P4PASSWD=pass
export P4USER=user
export P4CLIENT=Sonar
export PATH

Defining client workspaces 
To define a client workspace:


1.

Specify the workspace name by setting P4CLIENT; for example, on a UNIX system:

$ P4CLIENT=bruno_ws ; export P4CLIENT

 

2.

Issue the p4 client command.

Perforce displays the client specification form in your text editor.


3.

Specify (at least the minimum) settings and save the specification.

The minimum settings you must specify to configure a client workspace are:

 

Workspace name

The workspace name defaults to the client machine's hostname, but a client machine can contain multiple workspaces. To specify the effective workspace, set P4CLIENT.


Client root

The client root is the top directory of your client workspace, where Perforce stores your working copies of depot files. Be sure to set the client root, or you might inadvertently sync files to your client machine's root directory.

Note:
To specify server settings on the command line, use the -p flag. For example:
p4 -p localhost:1776 sync //depot/dev/main/jam/Jambase

 

Reference:
http://www.perforce.com/perforce/doc.current/manuals/p4guide/02_config.html#1069873 
http://www.perforce.com/perforce/doc.current/manuals/p4guide/02_config.html#1071378 
http://www.perforce.com/perforce/doc.current/manuals/p4guide/01_install.html#1070774

 from: http://community.scmgalaxy.com/pg/blog/read/19398/how-to-setup-p4-in-linux-unix

posted @ 2012-11-12 19:39  CCJPP  阅读(3718)  评论(0)    收藏  举报