Perforce Working with Local Files
When depot files are synchronized to the workspace, perforce normally puts read-only files on local disk. To edit files or to make them writable one have to open them. One also have to open files to add or delete from the depot.
Here, open doesn't mean opening file in application, it means file is open for submit.
1. How to open file for edit
#p4 edit test.c
edit command is used for editing file locally.
Opening files for editing makes them writable so we can edit them locally. These changes are local and not visible to other until we submit our open files to the depot.
2. How do I know which files I am working on.
#p4 opened
opened commangs list all files open for edit.
3. How do I know who others are working on file.
#p4 opened -a test.c
-a flag lists opened files in all clinets
4. How do I know which files I have changed
Is helpful to ensure, are opened files really changed before submitting.
#p4 diff -sa
-sa flag lists opened files that are different from the revision in the depot
We can also view the changes content of changed files.
#p4 diff
without -sa flag It will also display changed contents of files.
diff command compares depot revision file and workspace file for changes.
5. How do I add new file to the depot
#p4 add newadd.c
add command is used to add a new file to depot.
file can only be added if they are in current workspace view, if not then first move them to withing current workspace view then run add command.
perforce wildcards won't be working in new files to be added
6. How could i add entire directoy to the depot
perforce don't understands directory. so to add whle directory to the depot find command is used to search for the files in directory and it out put is given to p4 command to add each files.
#find . -type f -print | p4 -x- add -f
By doing this we don't need to do anything, perforce will create diretories it self
7. How to delete file from the depot
#p4 delete test.c
delete command opens file to be deleted, it also them from the workspace and from t he depot when submit command is run.
8. How to create duplicate file/directory or clone existing file/directory
How to integrate file/directory
integrate command is used to create a clone of existing file/directory
#p4 integrate test.c hi.c
#p4 submit
this create a clone hi.c for test.c and opens up hi.c file (for branching) and just need to submit.
In the same way we can create a clone for directory
#p4 integrate projectA/... projectB/...
#p4 submit
Its's also possible to copy file/directory to other place in workspace and use add command to open them as they are new files. But, in this way it won't inherit file/directory history from their originals
9. How to modify file as I clone it
cloned files are copied in to workspace first, and will appear as a read-only files. To modify them after integration reopend them with reopen command. This makes them writable at lease until we submit it.
#touch case.c
#p4 integrate case.c if.c
#ls -l
#p4 reopen if.c
#ls -l
#p4 submit if.c
10. Ranaming files/directories
Renamig files/directories is just like cloning, the only difference is we have to delete originating file
#p4 integrate hat1.c hat01.c
#p4 delete hat1.c
#p4 submit
Here, we integrated hat1.c to hat01.c and deleted originating hat1.c, this will also keep history.
Same for the directories.
#p4 integrate www/prod/... www/products/...
#p4 delete www/prod/...
#p4 submit
This will rename www/prod to www/products
11. How to replace file contents with other file.
to replace file content of welcome.c with the content of hello.c
#p4 integrate -i hello.c welcome.c
#p4 resolve -at
#p4 submit
-i flag enables integration with files that have no integration history. Normaly, p4 integrate command refuses to integrate changes if there is no prior integration history between the source and target, because it has no way to identifying the base for its merges. So -i flag forces baseless merges and tells p4 resolve just to use first added revision as the base
resolve command merges the open files with other revisions or files.
-at flag performs an automatic resolve that skips the merging instead it automatially accepts their version of file. It overwrites any changes made to the file in the client workspace
12. How to swap file contents.
swapign file content is similar to replacing files contents.
To replace files contents fo first.c and second.c
#p4 integrate -i first.c second.c
#p4 integrate -i second.c first.c
#p4 resolve -at
#p4 submit
13. How to locking files
Once you opened files in perforce for editing,perforce will warn others it they open the same file in their workspace even it won't prevent others from submitting their changes before you submit them.
To prevent others from submitting changes first, opened files must be lock. lock command is used for that.
#p4 lock
14. How to change the file type of existing file
When file is submitted, perforce records it file type accordingly. That is the filetype that stays with it revision to revison an also inherited to the files branched from it
To change file's file type edit command is used
#p4 edit -t +w case.c
-t flag changes the default file type detected by perforce to the given type.
15. How to check what is the file type of file
#p4 filelog case.c
displays filetype of file case.c
file type can also be change by reopen and open command in the same way.
16. How to revert files
To discard changes that made to open file is possible using revert command.
#p4 revert case.c
revert command doen't save backup copies of your changes workspace file. It just overwrites them with the fresh copies from the depot files.
17. It is possible to change local/workspace files without edit/open them.
We are free to change the workspace files to edit them without open/edit command by changing their files permissions. But, we won't be able to submit them to the depot.
18. How do I know which files are modified locally.
#p4 diff -se
diff command is used to view change between workspace and depot.
-se flag lists unopened files that don't match their depot counterparts
To open them for editing and submit changes, command given is
#p4 diff -se | p4 -x- edit
19 How do I know which files are deleted locally.
#p4 diff -sd
-sd flag lists unopened files that are missing from the client/workspace
When depot files are synchronized to the workspace, perforce normally puts read-only files on local disk. To edit files or to make them writable one have to open them. One also have to open files to add or delete from the depot.
Here, open doesn't mean opening file in application, it means file is open for submit.
1. How to open file for edit
#p4 edit test.c
edit command is used for editing file locally.
Opening files for editing makes them writable so we can edit them locally. These changes are local and not visible to other until we submit our open files to the depot.
2. How do I know which files I am working on.
#p4 opened
opened commangs list all files open for edit.
3. How do I know who others are working on file.
#p4 opened -a test.c
-a flag lists opened files in all clinets
4. How do I know which files I have changed
Is helpful to ensure, are opened files really changed before submitting.
#p4 diff -sa
-sa flag lists opened files that are different from the revision in the depot
We can also view the changes content of changed files.
#p4 diff
without -sa flag It will also display changed contents of files.
diff command compares depot revision file and workspace file for changes.
5. How do I add new file to the depot
#p4 add newadd.c
add command is used to add a new file to depot.
file can only be added if they are in current workspace view, if not then first move them to withing current workspace view then run add command.
perforce wildcards won't be working in new files to be added
6. How could i add entire directoy to the depot
perforce don't understands directory. so to add whle directory to the depot find command is used to search for the files in directory and it out put is given to p4 command to add each files.
#find . -type f -print | p4 -x- add -f
By doing this we don't need to do anything, perforce will create diretories it self
7. How to delete file from the depot
#p4 delete test.c
delete command opens file to be deleted, it also them from the workspace and from t he depot when submit command is run.
8. How to create duplicate file/directory or clone existing file/directory
How to integrate file/directory
integrate command is used to create a clone of existing file/directory
#p4 integrate test.c hi.c
#p4 submit
this create a clone hi.c for test.c and opens up hi.c file (for branching) and just need to submit.
In the same way we can create a clone for directory
#p4 integrate projectA/... projectB/...
#p4 submit
Its's also possible to copy file/directory to other place in workspace and use add command to open them as they are new files. But, in this way it won't inherit file/directory history from their originals
9. How to modify file as I clone it
cloned files are copied in to workspace first, and will appear as a read-only files. To modify them after integration reopend them with reopen command. This makes them writable at lease until we submit it.
#touch case.c
#p4 integrate case.c if.c
#ls -l
#p4 reopen if.c
#ls -l
#p4 submit if.c
10. Ranaming files/directories
Renamig files/directories is just like cloning, the only difference is we have to delete originating file
#p4 integrate hat1.c hat01.c
#p4 delete hat1.c
#p4 submit
Here, we integrated hat1.c to hat01.c and deleted originating hat1.c, this will also keep history.
Same for the directories.
#p4 integrate www/prod/... www/products/...
#p4 delete www/prod/...
#p4 submit
This will rename www/prod to www/products
11. How to replace file contents with other file.
to replace file content of welcome.c with the content of hello.c
#p4 integrate -i hello.c welcome.c
#p4 resolve -at
#p4 submit
-i flag enables integration with files that have no integration history. Normaly, p4 integrate command refuses to integrate changes if there is no prior integration history between the source and target, because it has no way to identifying the base for its merges. So -i flag forces baseless merges and tells p4 resolve just to use first added revision as the base
resolve command merges the open files with other revisions or files.
-at flag performs an automatic resolve that skips the merging instead it automatially accepts their version of file. It overwrites any changes made to the file in the client workspace
12. How to swap file contents.
swapign file content is similar to replacing files contents.
To replace files contents fo first.c and second.c
#p4 integrate -i first.c second.c
#p4 integrate -i second.c first.c
#p4 resolve -at
#p4 submit
13. How to locking files
Once you opened files in perforce for editing,perforce will warn others it they open the same file in their workspace even it won't prevent others from submitting their changes before you submit them.
To prevent others from submitting changes first, opened files must be lock. lock command is used for that.
#p4 lock
14. How to change the file type of existing file
When file is submitted, perforce records it file type accordingly. That is the filetype that stays with it revision to revison an also inherited to the files branched from it
To change file's file type edit command is used
#p4 edit -t +w case.c
-t flag changes the default file type detected by perforce to the given type.
15. How to check what is the file type of file
#p4 filelog case.c
displays filetype of file case.c
file type can also be change by reopen and open command in the same way.
16. How to revert files
To discard changes that made to open file is possible using revert command.
#p4 revert case.c
revert command doen't save backup copies of your changes workspace file. It just overwrites them with the fresh copies from the depot files.
17. It is possible to change local/workspace files without edit/open them.
We are free to change the workspace files to edit them without open/edit command by changing their files permissions. But, we won't be able to submit them to the depot.
18. How do I know which files are modified locally.
#p4 diff -se
diff command is used to view change between workspace and depot.
-se flag lists unopened files that don't match their depot counterparts
To open them for editing and submit changes, command given is
#p4 diff -se | p4 -x- edit
19 How do I know which files are deleted locally.
#p4 diff -sd
-sd flag lists unopened files that are missing from the client/workspace
No comments:
Post a Comment