p4 quick reference guid

来自大神的总结
First of all, compared to git, p4 is similar to svn, which is client-server mode, there is one server side. While the git is distributed version control system.
Since we changed from git to p4, so I list the p4 cmd vc git cmd for smoothly transfer.

0 p4 couldn’t automatically find the files that you edit by default. So keep in mind when you want to change one file
p4 edit or p4 open that file

  1. git status (show the files you modified/deleted/newly created)
    p4 opened(show the files you modified/deleted/newly created)
    1.1 p4 filelog some_file
    show you all the changes for this some_file
  2. git commit -a -m “check in note” (-a means check in all modified files, -m gives a checkin note)
    p4 submit –d “xxxx”
  3. git push (push your commit into the repo)
    no need in p4, p4 submit will upload the code to the deposit directly. No local deposit.
  4. git checkout (revert your local changes)
    p4 revert
  5. git diff (diff the file with the repo)
    p4 diff
  6. git pull (update your local checkout to the most update repo)
    p4 sync . . . (dot dot dot means recursively update all the files in this current dir)
  7. git add (add newly created files for commit)
    p4 add
    p4 delete some_file
    you don’t want this file, then this file will be dropped.
    To add a new or modify a file, all you need to do as
    git add
    git commit -m ‘you comments’
    git push
    p4 add files
    p4 submit(recommend that you edit your comments in the vim terminal)

to bring up one p4 tree, first you need to setup your env with the following variables.
setup your p4 tree
setenv P4PORT perforceserver:1666 //use this all the time
setenv P4USER xxx //(change xxx to your name)
setenv P4CLIENT xxx_df //(you could have as many as p4clients you want, every p4 tree need one different and unique P4CLIENT.
So you’d better use some script or shell skills to setup the this env for different p4 tree.
All you need to change is the P4CLIENT for different p4 tree.
Setenv P4DIFF gvimdiff/vimdiff/tkdiff //optional for the diff tools for you.

After done this, just type p4 client in terminal , you will get your p4 client view, such as
//
Client : xxx_df( it is the same as the P4CLIENT in the env)
Update:xxxx
Access:xxxxx
Owner:xxx(it is the same as the P4USER in the env)
Host:cpfc001
Description:
Xxxx
Root : /project/moksha/b0/dv/xxx/df_b0
Options: noallwrite noclobber nocompress unlocked nomodtime normdir
Submitoptions: submitunchanged
LineEnd: local
View:
//depot/dhyana/IPs/B0/DF_B0_V0mukti_df_platinum_drop/... //xxx_df/...
All you need to change is to
1makes sure that the Root path is unique, that is the path that you download the tree.
2 View
The left is the tree in the depot that you want to download the right is the client name

Tips:
1 ... means recursively

Then you could down load the entire tree.

//useful tips and useful cmds for you
1 how to copy other peoples P4clients.
a)For example, if you want the same tree as me, then p4 clients –u shangzheng |grep xxx, you will find my p4client
b) p4 client –o xxx_df >temp_file
then you could find my p4client configuration in the temp_file
2) refresh the tree anyway
P4 sync –f some_file or p4 sync –f ...(refresh the entire files recursively in this dir)
3) –n option,
P4 sync –n means I don’t really update the depot, but it will show which files will be updated.
P4 revert –n xxx means I don’t really revert the changes, but it could tell us if the file is changed or not.
4) p4 resolve
When p4 sync ..., you might face the resolve issue.
If no conflict, usually all your operation is :

  1. p4 sync ...
  2. p4 resolve ...
    a) if no conflict, you just need to choose the am(accept merge)
    b) if conflict, you need to e(edit)
    when the file is open, you search the === in the file, then you will find the conflict place, then you choose the right code segment, and save and exit, the conflict will be solved, then choose the am again.
  3. when you check in is rejected, how to resubmit
    You might need to sync the tree, and solve the conflict or solve the merge, then you use the p4 submit –c xxxxx(CL) to submit your change. Before the change you could also use the p4 change xxxx(CL) to change the comments or the files that you want to check in.
  4. sync to a previously version.
    P4 sync @CL
  5. p4 help some_cmd
    To see the help for the cmd
  6. p4 shelve and p4 unshelve
    When you want to share some code with other people and don’t want this change to be uploaded into the depot, then the p4 shelve and unshelve is very useful. The code writer could p4 shelve, and uploaded, the p4 will tell you that a shelve version had been give to you , you tell the people who want the code the shelve number, she/he will use p4 unshelve –s xxxx(shelve number), then she/he could get all your changes but no affect on the depot.
  7. when you don’t want to check in the change
    Just don’t save the p4 submit content for twice, then the p4 will interrupt this time submit, all the file state is not changed.
  8. p4 annotate
    P4 annotate some_file >sf will show all your changes to the some_file,all the line will begin with a number, which tells you the lastest changes on this line.
  9. p4 have
    If you want to see if you have uvm_reg.svh in the depot, you just need to use
    P4 have ... |grep uvm_reg_svh
    获得当前目录的p4版本号: p4 changes -m1 #have
原文地址:https://www.cnblogs.com/yanli0302/p/10942726.html