P4 sync issue-File not getting deleted - perforce

I have a workspace with set of files.But i observed that when i delete a file from perforce and do "p4 sync".The file is getting not deleted from the workspace.
But p4 sync -f deletes the file.

p4 sync will only delete a file from the workspace if:
the head revision of the depot file is deleted (check p4 files FILE)
you are currently synced to a different (not deleted) revision of the file (check p4 have FILE)
you do not currently have the file open (check p4 opened FILE)
The only one of these conditions that is affected by the -f flag is #2, so I suspect you had the file in your workspace but weren't on record as having synced it from the server (e.g. the file was put there outside of Perforce, or there was a sync -k, or something like that).

Related

How to I get the Perforce repo version of an file that was accidentally edited?

I accidentally edited the wrong file locally. The file is in a Perforce repo. What would be the best way to get the repo version, discarding the edited version and not changing other (edited) files?
For the question at Is there an equivalent to git stash in perforce? I see that p4 shelve could be a possibility?
Is another possibility to delete the file? And then follow Recover deleted files from Perforce with a p4 sync -f?
If the file is not open and you want to discard the edited version, either of the following will do the trick:
# Overwrite the local (unopened) file IFF it's different from the depot version
p4 clean FILE
# Overwrite the local (unopened) file no matter what.
p4 sync -f FILE
If the file is not open and you want to discard your local edits for now, but keep a copy of them (without submitting them):
# open the file for edit
p4 edit FILE
# shelve your local changes on the server for later recovery
p4 shelve FILE
# revert an opened local file to the depot version
p4 revert FILE
If the file is already open for edit and you just want to discard your local changes without shelving:
# revert an opened local file to the depot version
p4 revert FILE

sync cleanly to another perforce label

TL;DR: How do I sync an existing p4 workspace to a new label, so that all my previous changes are undone, and it is as good as a new sync?
Hi,
I have a perforce workspace synced to a label L1.
I added/deleted/edited a few files
I moved a few files inside a folder (mv a.txt b.txt new_folder/)
I want to cleanly sync this workspace to label L2 now.
I already removed all shelved and pending changelists, then tried
p4 reconcile -w ... && p4 revert -w ... && p4 sync ...#L2
Looks like it almost works, except that the files I moved inside a new folder do not get synced (p4 sync -f works though). But I do not want to use p4 sync -f on the entire workspace, as it would resync the unchanged files as well.
I am sorry if this question has been answered before, I am pretty new to perforce, so maybe could not find the correct terms to search for.
The ... path limits the scope of each operation to the current directory; if you ran those commands from a different directory than the one you moved the files to, that may be why they didn't get synced. I'd do:
p4 revert //...
p4 clean //...
p4 sync #L2

How to do I get files I deleted locally but didn't commit the changes?

I have deleted some files/folders in my local machine but I did not commit the changes to repository.
How to get the deleted files back?
I am not getting the deleted files after performing the p4 sync -f. Why I am not getting the deleted files after the force sync?
If you haven't reverted the changes Perforce will still think you want to delete those files so won't restore them.
You need to go to the pending changelist and do a "revert" on those files to get them back.
Use the "p4 revert" command:
p4 revert -c default //...
This "revert[s] every file open in the default changelist to its pre-opened state."
Source
If you don't want to revert all the files, move the files you want to revert to a separate changelist and use the "-c" option.
If you only have a few files to revert you can specify the name of the file:
p4 revert lib/libopenssl.a include/openssl.h
for example, reverts exactly those two files (thanks to Bryan).

how to sync the perforce client only with the files of a particular change list using p4 sync command

I'm trying to sync only the files modified in a particular change list to p4v.
Suppose in a perforce directory //demo/test I have 10 files out of which only 3 are modified as part of change list number 1234. I want only 3 files to be synced up. I have tried below options but it did not work.
p4 sync //demo/test...#1234;
This command says the files are updated but i don't see the files synced up.
p4 sync -f //demo/test...#1234;
This command is syncing all 10 files in the directory.
Use
p4 sync //demo/test...#1234,1234
or
p4 sync //demo/test...#=1234
When running tests like these, remember that 'p4 sync' won't sync a file that you already have, which is why you found the need to run 'p4 sync -f' to force the files to be sent even though the server knows you already have them. If you want to clear the server's memory of the files that you have, you can run
p4 sync //demo/test...#none
which will remove all the (p4-managed) files matching '//demo/test...' from your workspace, and then 'p4 sync' will bring them back the next time.
Oh, and since 'test' is a directory, the pattern
//demo/test/...
is preferred to
//demo/test...
since '//demo/test/...' matches only the files in the test directory, while '//demo/test...' will also match the files in the '//demo/test1', '//demo/test-and-set', and '//demo/testarossa' directories (if those should happen to exist).

Perforce "p4 sync" not working properly

Totally confused with the strange behavior of "p4 sync". Tried running the following commands
Note: The filename is not present in workspace
p4 sync //depot/filename
--- shows that files are up-to-date
p4 have //depot/filename
--- shows files not on client
Thought may be the perforce server thinks the file is present in its client's have database. So deleted the file using
p4 sync //depot/filename#none
--- shows files up-to-date
p4 sync //depot/filename#head
--- shows files up-to-date
Finally when I say
p4 have //depot/filename
--- shows files not on client
Then I did
p4 sync -f //depot/filename#head
--- shows //depot/filename - deleted as c:/workspace/filename
and in the end
p4 have //depot/filename
--- shows file not on client.
Any idea what could be the issue here?
Run "p4 files //depot/filename" and you will see that it is a deleted file.
If an older version of the file were present on your client (i.e. "p4 have" said there was something there), "p4 sync" would remove it. Since the file is already not present on your client, you are already "up to date".
Running "p4 sync -f" forces the issue and attempts to delete the local file even though the have table says nothing is there. (If you'd added a brand new file in its place and hadn't done "p4 add" yet, that file is now lost forever -- be careful when using "p4 sync -f"!)

Resources