How to create a perforce empty changelist from command line

11,901

Solution 1

If you're using the command line interactively, the regular "p4 change" command is the way to go:

p4 change

This opens the changelist spec in your editor so you can fill it out, and saves the changelist when you save the file in your editor and exit it.

If you're scripting, you can use "p4 change -i" but you need to make sure to feed it a valid changelist form via stdin. The "p4 change -o" command gives you the same form you get from "p4 change" (via stdout instead of your editor), so all that's left is to fill out the description and/or modify the list of files to be included. The --field option is useful here:

p4 --field "Description=My pending change" change -o | p4 change -i

If you want the new changelist to be empty rather than inheriting open files from the default changelist, blank the Files field:

p4 --field "Description=My pending change" --field "Files=" change -o | p4 change -i

Solution 2

Just using "p4 change" will open up the change form in the editor and upon saving a numbered change is created

Solution 3

My p4 doesn't understand --fields option. The following worked for me.

#Powershell commandlet
echo "Change: new`nClient: <client-name>`nUser: <user-name>`nStatus: new`nDescription: NewCL"|p4 change -i

Replace the items in <> brackets.

Here is the output of just the echo part.

#Powershell commandlet
PS C:\Users\sahil> echo "Change: new`nClient: <client-name>`nUser: <user-name>`nStatus: new`nDescription: NewCL"
Change: new
Client: <client-name>
User: <user-name>
Status: new
Description: NewCL

As you can see, the echo command just constructs a formatted string which p4 change -i accepts.

`n is used above for new line.

Note that I have excluded Files, as I wanted the change list to be empty.

Update - I updated my perforce installation and now p4 understands --fields option.

Share:
11,901
Max
Author by

Max

Full stack developer, Game Programmer and designer

Updated on July 28, 2022

Comments

  • Max
    Max almost 2 years

    i'm trying to create an empty changelist from command line using the command p4 change -i but seems that this command does nothing, i don't get any error/success message, the command line simply return nothing and i have to kill it with ctrl+c.

    My p4 client works, i'm able to see all my info and doing all other operations correctly, seems to have problem only to create a new pending changelist.

    Anyone experienced the same issue?

    P.s. I've checked the P4V way to create an empty changelist and it actually using the p4 change -i command without any issue, but if i try to use the same command from cli it will silently fail.

  • Max
    Max over 7 years
    thanks also for the --field part, it would be my next question :D
  • Max
    Max over 7 years
    can i use the --field operator also for retrieving data (like return only the description) of a changelist? Sorry for asking in a comment
  • Samwise
    Samwise over 7 years
    Try "p4 -Ztag -F %Description% change -o CHANGE"
  • Sahil Singh
    Sahil Singh about 7 years
    I am getting Invalid option: --field.
  • Samwise
    Samwise about 7 years
    Update your p4 executable; this is a new feature in 2016.1.
  • Max
    Max about 7 years
    does not recognise the --field because is outdated, if you update it you will be able to use it (and is pretty helpful)
  • Sahil Singh
    Sahil Singh about 7 years
    Thanks, updating worked for me. I do not understand why --fields is mentioned in "p4 help undoc", which is for "Unsupported or obsolete Perforce commands and options", while "p4 --help" doesn't mention it.
  • Samwise
    Samwise about 7 years
    It's because it's an unsupported option. Making it "supported" would have inevitably meant writing a lot of documentation showing how to use it with every single spec, so it was either make it undoc or add a lot of annoying limitations to it to make it easier to document. ;)
  • Sahil Singh
    Sahil Singh about 7 years
    @SamStafford Are you saying that new features first get added to unsupported section, and as they get improved and more time is spent on them they get added to supported section?
  • Samwise
    Samwise about 7 years
    In some cases but not always or even generally. Features have started as "undoc" (and sometimes stay there) if they're experimental or if they're "power user" features that are difficult to support for the general population. "p4 flush" is a good historical example (it eventually became "p4 sync -k" but it was undoc for a long time because it's very much a power user feature that can cause problems for normal users that don't understand it). Most features don't start life as undoc though.
  • user3664223
    user3664223 about 5 years
    At my end its failing p4 --field "Description=My pending change" --field "Files=" E:\MyDriver\MyFile.txt change -o | p4 change -i . Error in change specification. Can't include file(s) not already opened. Open new files with p4 add, p4 edit, etc.