Is there any way to sync only the latest change list number changes.
For example if the latest change number is 1234 and has 2 files in submitted changelist. I want to sync only those 2 files not the complete folder.
The below command is syncing only the 2 files
p4 sync -f //demo/osb/Test/...#=1234;
I want to pass this value dynamically as this value will change.
I have tried the below commands but none are working.
p4 sync -f //demo/osb/Test/...#head;
p4 sync -f //demo/osb/Test/...#=head;
p4 sync -f //demo/osb/Test/...#head; --> this is updating the complete folder
p4 sync -f //demo/osb/Test/...#=head; --> this is updating the complete folder
Thanks for the help!!
One way to do this would be to use two commands:
p4 -F %change% -ztag changes -m1 -s submitted //demo/osb/Test/...
p4 sync //demo/osb/Test/...#=NNN
The first command tells you the change number of the latest submitted change. The second command syncs the files changed in that changelist.
Depending on your shell, you could perhaps combine them:
p4 sync //demo/osb/Test/...#=`p4 -F %change% -ztag changes -m1 -s submitted //demo/osb/Test/...`
(Whew! That's a mouthful!)
You have to have a fairly recent client version for the '-F %change%' syntax to work; if you're having trouble with this part of the solution, check your client version.
Related
I want to be able to sync ONLY the differences in the depot into my workspace.
I do not want to re-sync all the source files which already match.
I currently can see the difference with this command:
p4 diff -sd //depot/source/...
But when trying to use this command to sync the depot differences to my local workspace:
p4 diff -sd //depot/source/... | p4 -x - sync -f | p4 //depot/source/...
I receive this message in the terminal:
"- must refer to client"
Note: Prior to performing all of the above command I set my client using
p4 set P4CLIENT=MYWORKSPACE
To sync only the files that have been updated on the server since you last synced, do:
p4 sync
The default behavior of the p4 sync command is to sync only changed files; you don't need to perform any special gyrations to make that happen.
The server's notion of what's different between the server and your workspace is dependent on its records of what it sent you the last time you synced. If you've messed around with your workspace in unsupported ways (i.e. you've modified files that Perforce made read-only without "opening" them for modification), those records have been invalidated. You can fix this one of two ways, depending on what you want to do with your modifications:
p4 reconcile
will open the files you modified, allowing you to choose between reverting the modifications or submitting them.
p4 clean
will simply overwrite your modifications, similar to a p4 sync -f, but p4 clean will do a diff to figure out which files you modified and will only re-sync those files.
After a while of working with perforce I was left with a lot of still open change lists.
To clean up I want to get rid of a subset of them.
So here is what makes this complicate:
For a subset of the changes the host of the client has changed.
Some changes contain shelved files.
Files from the change list may be deleted or moved.
When one or more of above points are true for a change list, p4v (the visual client) will not allow you to delete the change list.
So what is an effective way of deleting these change lists?
First of all, perforce refuses to work on any change lists if the host differs in their workspace. So step one is to change the host of the workspace to the current one. This can easily be done with the visual client p4v. Open the properties of a workspace, choose edit and change the host.
Then you can use the command line to get rid of the pesky change list(s):
# to delete a changelist
CLIENT="name_of_your_client"
CHANGE="number_of_the_changelist_to_delete"
p4 -c $CLIENT shelve -c $CHANGE -d //... # Delete all shelved files from it.
p4 -c $CLIENT revert -k -c $CHANGE //... # Revert all files from changelist (only metadata).
p4 -c $CLIENT change -d $CHANGE # Finally delete the changelist.
After the last command the change list will be gone forever.
Fixing the hostname can be done from the command line like this:
client_hostname="$(p4 client -o ${CLIENT} | grep "^Host" | awk '{print $2}')"
p4 client -o ${CLIENT} | sed "/^Host:/ s=${client_hostname}=${HOSTNAME}=" | p4 client -i
Had the same problem some time ago and wrote a script (p4-delete-changelist) that overcomes all of these problems (and another one - deleting p4 fixes).
Note that the script depends on another file in the repository.
My workflow for testing my changes to our source code on a remote machine is the following:
1) On local machine: Shelve changes that I'd like to test
2) On remote machine (ssh):
$ p4 revert //...
$ p4 sync
$ p4 unshelve -s <changelist number>
$ ./run_test_scripts
This seems to work fine when I've only made changes to files that already exists. If I've added new files these will be created during p4 unshelve, but not deleted during p4 revert. The documentation says that this is what p4 revert does so it isn't unexpected, but causes some problems if I want to test the same files again:
$ p4 revert //...
<some file>#none - was add, abandoned
$ p4 sync
File(s) up-to-date.
$ p4 unshelve -s <changelist number>
Can't clobber writable file <some file>
Is there way I can delete the files abandoned Perforce?
I think what you're looking for is p4 revert -w. From the help:
The -w flag causes files that are open for add to be deleted from the workspace when they are reverted.
Note: I'm using the 2013.2/719516 client against a 2013.2/708877 server, in case that switch was added recently...
Edit: just reread your question - this is a workaround, perhaps not a full solution...
There is a setting in P4Win that allows you to overwrite files when unshelving:
Overwrite workspace files even if they are writeable
I normally use that in combination with another option (again in the gui):
Revert checked our files before unshelving
They solve my problem.
Looking in the console output while running this from the gui, it looks like it is the -f parameter in the unshelve command.
p4 unshelve -s <changelist> -f -c <changelist> <files>
I thought I could use P4 sync -f #Changelist# to sync only those files in Changelist#, but it is syncing the entire directory. How can I limit the sync to only the files in Changelist#?
If you want to limit a sync to only the files in a specific changelist, you can do the following:
$> p4 sync #changelist,#changelist
E.g.
$> p4 sync #604286,#604286
To sync only the files contained in a changelist, you can use the #= syntax:
p4 sync #=12345
If I understand the question correctly - You already have a tree with some files. Now there is a new change-list and you want your tree to be updated in such a way that only files listed in this new change list are synced leaving rest of the tree intact/unaffected.
If this is the case then answer is - p4 sync #=changelist. But just to be safe first try with p4 sync -n #=changelist option.
If you try with p4 sync #changelist you will see that your whole tree is updated/deleted. Just try with
p4 sync -n #changelist | more
To sum up the other answers and add one of my own: roll 1d3 and choose from this table.
p4 sync -f #=CHANGE
p4 sync -f #CHANGE,CHANGE
p4 -F %depotFile%%depotRev% files #CHANGE,CHANGE | p4 -x - sync -f
Each time we do a build, we have to record the changelist number of source files for tracking. We have different projects (under different directories) and they are synced at different changelist number. May you please show me how can we get the changelist number of a specific directory?
Also, there's p4 changes -m1 //path/to/your/project/...#have which, if run in the client workspace that synced the files for building, will give you the highest changelist number of the files in the workspace.
You can also use the short version p4 changes -m1 #have if you don't want to specify the directory.
If you are using a shell for which "#" is a comment character like bash, remember to escape it as follows: p4 changes -m1 \#have
p4 cstat //path/to/your/project...#have |grep -B1 have|tail -n2
#thegeko, this does not require high max_scanrows perforce limits
If your build system always syncs to head on the directory before building, you can use p4 changes -m 1 //path/to/your/project/... to get the head changelist number for that directory.
If you go with this method, I would suggest running the changes command before syncing, and then explicitly syncing to that changelist. That should eliminate the chance of someone checking in between the changes command and the sync command.
I use the "lazy manual way" (aka I don't know better) within the P4V client:
Use this in the "Submitted" tab filters: //yourproject/...#>have
And it will show you which CLs you haven't synched, note the oldest one.
Remove the #>have filter and see what's the CL that came before the one you just noted.
From within the directory:
p4 changes -m1 //...#have
Using just the workspace path, p4 changes -m1 /path/to/your/workspace/...#have (or cd /path/to/your/workspace; p4 changes -m1 $(pwd)/...#have) gives you the highest changelist number of the files in the workspace. This is similar to the accepted answer above from user1054341 p4 changes -m1 //your-client-name...#have, but you don't have to remember the client name.
A path to a subdirectory in the client gives you the latest changelist in that subdirectory and its children, e.g. p4 changes -m1 /path/to/your/workspace/src/module1/...#have. This can be run from any directory within the workspace.
Omitting #have shows the latest changelist checked in to the depot.
These commands must be run from a directory in the workspace.
In my case, I just want to know what changelist number is opened (not syned to) in a specific directory. For that, I do:
p4 opened -s | cut -d' ' -f5 | uniq