When I add new files to my project which is managed by Perforce, how can I get a list of the new files I've added (the ones Perforce does not know about yet) so I can make sure I don't miss any in my changeset?
Something like 'svn status | grep ^\?' or 'git status' to show the unstaged, unknown files.
Thanks!
-Casey
Find the similar question on SO and check the other answers and comments too. There is no direct command available from command-line. But you can use a powershell script or a GUI for it.
The best answer is provided in the similar question linked to by Teja. However, if you want an easy command line solution that deals specifically with added files, you can do the following
find directory -type f | p4 -x- add
for normal files, and
find directory -type l | p4 -x- add
for links. (Letter 'el', not 'one' in above command)
Perforce simply refuses to add any files that are already in version control. The only problem is that this adds everything, including binary files.
For P4V, right-click on a folder in the workspace tree and click "Find File...". In "All or part of a file name", type "*.cs". Then sort by filetype - new files will have filetype "none".
Unfortunately there doesn't seem to be a way to apply multiple filters, e.g., "*.cs; *.aspx". So you have to filter one filetype at a time. Also, you have to be patient if there are thousands of files - the sorting mechanism won't work properly until the asynchronous find process has completed.
(The "Reconcile Offline Work..." option isn't working for me. I'm using P4V June 2009.)
You might take advantage of the p4 files command
find . -type f | xargs p4 files 2>&1 | grep 'no such file(s)'
You could even filter on file type like this.
find . -type f | xargs p4 files 2>&1 | grep 'no such file(s)' | grep 'cpp'
Here's a unix one liner using find and p4, fstat and awk that saved my bacon.
How to find untracked files in a Perforce tree? (analogue of svn status)
The perforce "reconcile" command with the "add files" and "preview" options will show new, un-added files, without adding them:
p4 rec -an
Related
I have a sandbox that I've completely reworked in the past several weeks. This includes modifying, creating, and deleting both files and directories within this sandbox.
How can I add all of these changes to a new change-list in Perforce? Can it be done with a single command?
I've tried find . -type f -print | p4 -x - add, but this gives me multiple errors for files, saying can't add existing file
Run:
p4 reconcile
This will open all the files. Follow it up with:
p4 submit
find . -type f -print | p4 -x - add
This adds all files from $PWD and its sub directories, but it prints the message can't add existing file for files already in perforce.
How do I add only new files which are not in P4?
For Perforce versions 12.1 and above, you can use the command p4 reconcile, which will reconcile any added, deleted, or edited files outside of Perforce. To use it specifically to add files, type p4 reconcile -a.
Just a note though, it doesn't do any harm to do the command you are doing. It issues a warning for any files already existing, but that's it. It will still add the files that don't currently exist in Perforce. Your command is the way I have done it until the p4 reconcile command was created.
For example, I have 100s of files checked out in a changelist:
//Development/MyProject/Version1.0/Coord/File1.cs
//Development/MyProject/Version1.0/Coord/File2.cs
...
//Development/MyProject/Version1.0/Coord/Filen.cs
//Development/MyProject/Version1.0/Common/File1.cs
...
//Development/MyProject/Version1.0/Common/Filen.cs
Similarly in some more directories. Now I want to checkout similar files in Version2.0
//Development/MyProject/Version2.0/Coord/File1.cs
//Development/MyProject/Version2.0/Coord/File2.cs
...
//Development/MyProject/Version2.0/Coord/Filen.cs
//Development/MyProject/Version2.0/Common/File1.cs
...
//Development/MyProject/Version2.0/Common/Filen.cs
I can do this by looking at what files have been checked out in Version1.0 and go to each directory in Version2.0 and checkout those files. This is tedious job.
Any aboveboard way of doing this?
From the linux/Unix/macOS shell, I suggest the following method. It would be significantly different in Windows unless you had unix tools installed there.
Check out all your Version1.0 files.
cd to your Version1.0 directory
Run the following command line:
p4 opened ... | sed 's/\#[1-9].*$//' | sed 's/\/Version1.0\//\/Version2.0\//' |
p4 -x - edit
Note: this would need some tweaking if any of your files have '#' symbols in their names. It's a quick-and-dirty fix. And credit to Bryan Pendleton above, who basically said the same thing much more briefly.
I know this is a strange question, but is there a p4 command that is the reverse of 'sync'? That is, I'd like whatever files are in my local workspace directory to be pushed to the depot.
I know your first thought is probably "but WHY?", and the answer is, it's complicated.
Reconciling offline work could help you. It pushes files that are added, or changed or deleted . Its a bit trickier with renamed files.
Out of curiosity. What exactly is "it's complicated"
Both 'submit' and 'shelve' can send file content from your local workspace to the depot.
In either case, you have to use 'add' or 'edit' first to mark the files to be sent to the depot. (How you do this depends on the client tool you're using.)
Here's a script, derived from the O'Reilly Perforce book
You probably want to start with
p4 sync -k ...
which makes perforce think it has synchronized to the current head, but in fact
makes no changes to the filesystem. So the below diffs will behave (to perforce) like changes to the current head.
# a reverse 'synchronize' (sync what's on disk with what's in the depot)
# see "practical perforce" (o'reilly) page 46
#
# changed files
p4 diff -se | p4 -x- edit
#
# deleted files
p4 diff -sd | p4 -x- delete
#
# added files
find . -type f -o -type l | p4 -x- add -f
I have not tested the above in isolation (it came from a longer script that has been widely used) but I believe it should work.
p4 changes -l ... shows us the list of check-ins and the description, but it doesn't show the list of files that were modified in the check-in. Is there a way to do that in one command, without the need to create a wrapper script that combines the output of another command like p4 describe or p4 file?
In Subversion, I can do this by running svn log -v.
The 'files' command can do what you're looking for. An easy way is:
p4 files //...#=<changelist>
That example will list the files modified by that changelist, under the view specified.
You can use the "describe" command to get the description of a changelist, along with the files affected.
For example, p4 describe -s <changelist> will describe the changelist, and the "-s" will prevent it from displaying file diffs.
One liner, list all changes made to a branch, with description and list of affected files, without showing the diff. Thanks to a combination of answers. Works on windows with Unix utils
p4 changes -s submitted //depot/xxx/yyy/zzz/... | grep -o "^Change [0-9]*" | cut -f2 -d" " | p4 -x- describe -s
Output:
Change 1753385 by user#clientspec on 2019/03/08 06:29:44
Changing the world
Affected files ...
... //depot/xx/yy/zz.h#6 edit
Change 1751752 by name#clientspec on 2019/03/05 15:24:00
I made a change to a file
Affected files ...
... //depot/xx/yy/zz.h#3 integrate