Rohit
Rohit

Reputation: 1720

Perforce: How do I get a diff of all changed files between branches?

I have two branches mainline and rcat. I have been working on rcat for a while now (multiple CLNs/Submits) and would like to merge into mainline. However, before I merge I need to submit the diff for a code review.

I want to obtain one unified diff between mainline and rcat branches. I have tried:

p4 diff2 -duw //depot/my/project/path/projectname/mainline/...  //depot/my/project/path/projectname/rcat/... >> diff.txt

This does not give me the files I added in rcat and also lists a bunch of unchanged files. How do I get a diff that:

  1. Has changes to existing files
  2. Has new files
  3. Ignores unchanged files

Thanks!

Upvotes: 3

Views: 8785

Answers (1)

Commodore Jaeger
Commodore Jaeger

Reputation: 33350

In the teams I've worked on that used Perforce, we'd typically merge from the development branch to the mainline, then perform the code review on the pending changelist on the mainline. From your example:

p4 integrate //depot/my/project/path/projectname/rcat/... //depot/my/project/path/projectname/mainline/...
p4 resolve -am
# Deal with any merge conflicts
p4 diff -du > diff.txt

diff.txt will have the changes to existing files, and show deleted files as having been emptied of their contents, but won't actually show new files. (My teams used Code Collaborator to do code reviews, which handles added files.)

Alternately, if you have a Linux-like diff handy, you could try (assuming you have mainline/... mapped into the mainline directory, and rcat/... mapped into the rcat directory):

diff -Nur mainline rcat > diff.txt

which will handle deleted files and added files as you'd expect. (You may want to integrate from mainline to rcat first so the changes that show are only those that were made to rcat.)

Upvotes: 5

Related Questions