Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to untrack changes in Perforce changelist without modifying local files (P4V 2015.2)?

Tags:

Note: this question is related to, but not a duplicate of How do you clear the default changelist without altering your worktree in Perforce. My argument is that, while similar, this question is specifically with regards to the P4V client.

Overview

Suppose I'm using perforce to track a file. The current state of the file (file1) is identical on the server Depot, and the local Filesystem For illustration purposes, I will also show the current 'state' of the default Changelist:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file1 | file1      | <empty>        |

If I make a change offline (file1 is now file2), perforce won't know about it yet (I am aware that ideally this shouldn't happen and that all changes should always be tracked, and that the file should have been write protected, but it can if perforce isn't running, the moon is in the wrong quarter, etc. so for the sake of argument, suppose that this did in fact occur):

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file1 | file2      | <empty>        |

If I Reconcile Offline Work... or have the file get added manually to the changelist, the changelist now is aware of this change:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file1 | file2      | file1 -> file2 |

If I then submit the changelist, the change it currently has tracked is applied on the server, and the changelist is once again empty:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file2 | file2      | <empty>        |

Question

Suppose I've made a change and tracked it. The local filesystem is changed (file2 is now file3), and the changelist reflects that:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file2 | file3      | file2 -> file3 |

Suppose then that I now want to move back to the state where the workspace/changelist is unaware of file2 having been changed to be file3, but without actually modifying the file on disk:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file2 | file3      | <empty>        |

note how filesystem still is in state file3, not file2

What would it take to do that? Is there a way to perform this action without backing up the change out of the workspace and reverting completely or running 'clean' and then re-applying the change offline?

I know I don't want to just 'revert' the change, because that reverts not just the state of the changelist but also of the file locally:

| Depot | Filesystem | Changelist     |
|-------+------------+----------------|
| file2 | file2      | <empty>        |

note how filesystem has lost state file3 and was also reverted to file2

TL;DR:

How can I 'revert' my changelist/workspace to no longer track a change without the file in my local filesystem being reverted, or modified in any way?

I'm using the P4V v2015.2

like image 303
Johannes Avatar asked Jul 18 '18 22:07

Johannes


1 Answers

Overview

It is not possible using just the P4V UI (at least in v2015.2).

However it is possible through the commandline, where the 'revert' command has a -k flag, which p4 help revert explains as:

The -k flag marks the file as reverted in server metadata without altering files in the client workspace.

I am aware that this was discussed in a similar question here: How do you clear the default changelist without altering your worktree in Perforce - but neither the question nor the selected answer mention the P4V client, so I'm writing a more detailed explanation below in case it benefits someone.

How to remove pending changes from a Perforce changelist without modifying the local files

  1. Right click anywhere in your workspace view and choose Open Command Window Here

    • The current working directory is not actually used by the command so what folder you are in does not matter.
    • We need this to set up the environment variables though, so running the command in a clean command line window may not work if you haven't set those up.
  2. Enter the following command: p4 revert -k -c default //...

    • The -k flag means to not modify local files when reverting the changelist
    • The -c flag specifies the changelist you want. Use default or the exact changelist number you want to untrack the files in.
    • The final argument specifies where (in relation to your workspace root) it should look for files to clear out of the changelist. //... means all files in the workspace. Note that this is always still limited to the files in the changelist you specified with -c!
  3. Once you've run that command it will list each pending change that was removed from the changelist.

    • The Perforce client won't actually reflect this change unless you press f5 or hit the refresh button, at which point you should see your changelist clear again.

Why would you do this?

Whether or not such an action should be performed is up to the reader's discretion, and the warning in the other answer should be taken into consideration.

My main use case has been where files already in the changelist were for some reason removed, moved, or renamed without those actions getting tracked.

Yes, ideally those changes should have been tracked, and I probably have to look into my workflow to avoid this in the future. Nonetheless, attempting to submit the changelist while in this state can cause errors since those 'pending changes' don't technically exist anymore.

To avoid this I've found it easiest to clear the changelist with the -k flag as described above, removing the old changes that were no longer representative of the local filesystem, and then running Reconcile Offline Work... on all relevant directories to get just the current latest state into the changelist, and then submitting that.

like image 52
Johannes Avatar answered Sep 28 '22 18:09

Johannes