Reputation: 30283
Is there an easy way to undo whitespace changes in Perforce?
I have a .vimrc script that trims trailing whitespace on save, but in certain branches of code, the owner of said code doesn't want whitespace diffs.
I typically have to make a copy of my file, revert the original file, then manually integrate the non-whitespace changes I made.
Is there a simple command in Perforce (or other UNIX tools) that can do this automatically?
p4 resolve
as a -dw
option for ignoring whitespace, but I don't know how I'd make the file resolvable in the first place.
Upvotes: 4
Views: 1596
Reputation: 71517
Assuming in this example your revision was #4
and your file is foo
:
p4 sync file#3
p4 edit file
p4 sync file
p4 resolve -dw
You can also do this across many files at the changelist level; sync back to previous change, open for edit, sync to your change, resolve with whatever options.
I think that when you do resolve -dw
it keeps the "yours" version of whitespace-only diffs, which in this case will be file#3
which is what you want.
Note that if you have individual lines with both whitespace and non-whitespace diffs you'll most likely get the whitespace diff along with the rest of the line since Perforce's merge operates per-line. If all else fails, find another merge tool that'll do the specific thing you want to do with the whitespace, set P4MERGE
to that, and do p4 resolve
;m
.
If your changes are still pending I think you can do something like:
p4 print -o depotRev file
p4 merge3 -dw depotRev file depotRev > merged
rm depotRev
then do:
diff file merged
to make sure the diffs look right before replacing your file
with merged
.
Upvotes: 3