Why does p4 flush not update my have list? - perforce

My p4 client version is P4/NTX64/2018.1/1705517.
I noticed that some files had accidentally been deleted in my workspace. I synced, but even so, the files did not appear.
I then ran the p4 have command and saw that it contained the missing files, and so p4 will not include those files in the sync.
Of course I can give the p4 sync command with the -f flag, but my workspace is rather large, so that would take a long time.
I then ran the flush command even with the -f flag thinking that it would correct my have list to reflect what I actually had on the filesystem of my workspace, but it didn't. What am I doing wrong?

p4 flush changes the have list to match whatever you tell it to match (if no arguments, then #head is the default). If that's not what your workspace actually contains, then the have list is now out of sync with the workspace, and future p4 sync commands will probably skip a bunch of files (exactly like you're seeing now).
The command you want is p4 clean, which syncs your workspace to match your have list. (If you have changes in unopened files, including "new" files that you haven't opened with p4 add, this will irrevocably blast them. Careful!)
If you want to open the files that don't match your have list, use p4 reconcile instead. (You can follow it up with p4 revert to discard the changes, or p4 submit to keep them permanently.)

Related

How to sync perforce client to reduced p4 client specs?

I have a large perforce client already synced. I realized that I'll only be working on a sub directory of the larger root folder I synced to.
Old p4 client specs
//Depot/largeFolder/... //Clinet/largeFolder/...
New p4 client
//Depot/largeFolder/samllSubDir/... //Clinet/largeFolder/smallSubDir/...
Now when I perform a p4 sync perforce doesn't remove the other folders which I don't want in my client.
I'm hesitant to do a p4 sync -f since I have files edited in the /largeFolder/smallSubDir/. I don't want them to get reset.
What is the right way to sync my client so that the other folders which are not in the new mapping are removed?
Note: My real mapping is complicated and deleting folders by hand is not realistic.
In the typical case, re-syncing a narrowed client will indeed remove the unmapped files. You don't say what happens when you try to do a sync (are there error messages?), so I can't say for certain what's going on, but these are the two first possibilities that come to mind:
Opened files will not be touched by a sync, ever. You need to revert them -- use the -k flag if you want to revert the files but keep your local copies, and then use the -k flag on sync as well so that it will continue to not touch them (while marking them as having been synced, or in this case un-synced).
Writable files will by default be left alone by a sync, and produce "can't clobber" warnings. Doing sync -k should suffice here if you want to keep the local files. Doing sync -f will blow away the local files even if they were modified (but only if they're not also open for edit -- see above).
Useful commands to run if you're trying to debug (pick any file that's not getting [un]synced that you think should be):
p4 sync <file> -- do you get an error message that tells you why the file isn't being removed?
p4 where <file> -- is the client mapping for that file not what you think it is?
p4 opened <file> -- is the file opened?
p4 have <file> -- did you even sync this file in the first place?
p4 files <file> -- does this file even exist in the depot?
Note that the fact that opened files will not be touched by a p4 sync means that your edited files will be safe from a sync -f, provided that you actually opened them for edit. If you didn't, run a p4 reconcile and then p4 sync -f is perfectly safe -- but if you don't get to the root cause first (i.e. are the unwanted files also opened for edit?), it might not be helpful either.

#have doesn't capture CLs of deleted files in Perforce

We are using the following P4 command for snapshot versioning.
p4 changes -m1 /path/to/files/...#have
I noticed that the above command doesn't capture CLs of deleted files if the CL is the head CL.
So it ends up having two artifacts with the same version but different files.
I was wondering how we can cover this edge case?
This is an artifact of the fact that deleted files aren't synced to the client and will therefore never be included in #have.
If possible, the best way to address this IMO is to capture the changelist at the time you sync to the head revision. Do:
p4 changes -m1 -ssubmitted /path/to/files/...
and then use that changelist to do:
p4 sync /path/to/files/...#CHANGE
Since submitted changelists are immutable (outside of edge cases like obliterate and +S files) you now have a guarantee that anyone else syncing to that same path#change will get the same set of revisions that's in your workspace.
Note that the p4 changes command will capture changelists with deleted revisions, even if those revisions are then skipped by the p4 sync!

Make the contents of a perforce directory exactly match the latest depot version

I would like to make the contents of a directory in a Perforce workspace be exactly the same as the latest depot contents. I want this to work no matter what has gone on in the workspace. (For example, editing files without opening them in perforce, creating unsubmitted changesets, etc.)
So far I have come up with running this series of commands, in order:
p4 clean ...
p4 revert ...
p4 sync ...
Will this do what I want? Is this the correct order? Is there a simpler way?
Those are the correct commands, and you do need all three:
revert is needed to discard changes to files you've opened
clean is needed to discard changes to files you haven't opened (including added files)
sync is needed to make sure you're at the very latest depot revision
You should either put clean after the revert or add -w to revert; otherwise files that were opened for add will be skipped by the clean (because they're open) and then revert will "abandon" them in the workspace (the -w option causes revert to delete/"wipe" added files instead of abandoning them). Other than that, I think the order is unimportant.

How to only receive get file changed by revision In perforce P4

In P4, I only want to pull file changed my client workspace from server. But When I use "p4 sync", this command get all files from server. So, How to get files changed from list revision ? with the files were existed on local and not changed, the command P4 sync do not need sync. My command is here:
p4 sync -f //depot/...#Revision
If you want to restore a file you deleted with p4 delete file, use p4 revert file, not p4 sync. p4 sync is for getting the changes that other people made to the files, not for altering the changes that you made.
There are three different reasons that the files in your workspace might differ from the current head revision in the depot:
A new revision has been submitted to the depot since the last time you synced.
You have opened the files (e.g. with p4 edit) and made changes to them that are not yet submitted.
You have modified the read-only synced files in your workspace without opening them.
(You don't say in your question which of these is the case, which is why you've gotten a couple of different answers that are based on different assumptions about your workspace state -- I'm guessing it's #3, personally, but I'll give the answer for each one so you can understand how it's "supposed" to work vs what's actually going on here.)
In case 1, a normal p4 sync command will update only the files with new revisions. If the revision you previously synced is the same as the head revision, p4 sync won't update it. This makes p4 sync very fast -- you can have a million files in your workspace, and if only one of them has changed since you last sync, only that one file is affected.
In case 2, no p4 sync command will update the files, in the interest of preserving your open changes. To submit your changes to the depot, use p4 submit; to discard them, use p4 revert. Again, only the open files are affected by these commands, so a revert operation affecting only a few files isn't slowed down by however many other files are in your workspace.
In case 3, your workspace is in an inconsistent state -- Perforce's standard workflow is that any time you modify a local file you should "open" it so that the server can track your local work (and optimize operations like sync, submit, etc, as well as alert other users who open those files simultaneously to potential conflicts). If you modify a file locally without modifying it, commands like sync will no longer work as well because the state of your client is not known to the server.
You can recover from an inconsistent state by using the p4 reconcile command (which will open all the inconsistent files so that you can either submit or revert them), or the p4 clean command (which irrevocably discards the inconsistent local changes, as if you'd done p4 reconcile immediately followed by p4 revert). These commands are significantly slower than a normal sync operation since they need to scan the entire workspace rather than only the changed files, but they are still significantly faster than a sync -f since only the changed files are actually re-transferred.

p4v doesn't delete new files added through `p4 add` after shelving

I've tried to shelve files today and checked the Revert checked out files after they are shelved option, and after shelving the files some files have been reverted, but some remained. It appeared that these were new files added through p4 add. Is it default behavior to not remove such files after shelving? Is there a way to remove them as part of shelving process?
What you did in P4V (shelve with reverting) is really a plain combination of two commands: shelve and revert. Behind the scenes, P4V will shelve your work (as it surely did) and then revert everything in your changelist.
Now, the revert command reverts p4 adds in such a way that they disappear from your changelist (the essence of reverting) but they remain on the local filesystem (to prevent inadvertent loss of code/data). Yes, you can argue that in this respect revert does not do a very good job of reverting your work completely, but obviously Perforce have decided to play it safe by not deleting your work.
As #Bryan Pendleton says, you can use p4 revert -w instead of plain p4 revert when you want to also delete your p4 adds from the filesystem. It's not a separate command, just a variant of p4 revert. However, there's no way to specify the -w flag (the -w behaviour) when running the "Shelve-and-Revert" combo action from P4V. (In fact, there's no way to specify -w even in the plain "Revert" action from P4V.)
I'm assuming you won't switch from P4V to the command-line (to run p4 shelve followed by p4 revert -w) just for this reason, so just remember that P4V has this little quirk and if needed, delete your local files after reverting them.

Resources