I often use git log -p <file>
or git log -p <directory>
to get a comprehensive summary of the changes in a file or set of files. It outputs a history of the commits affecting the files, together with a unified diff of each commit.
Using Perforce I can do p4 changes <file>
or p4 changes <directory>/...
to get a list of commits. But there does not seem to be an option to show the corresponding diffs.
Is there a Perforce equivalent I could use? If shell scripting is necessary, a fully working function would be nice.
If you want to know why I miss the feature, here are a few things that git log -p
lets me do extremely quickly:
.cpp
file to be modified?FOO
has been added to a file.git log -p shows the diff of a commit. git log - n shows the last n commits. git log --oneline shows a concise view of the short hash and the commit message. You can stack options on git log , as in git log -8 --oneline to show the last 8 commits in a condensed form.
The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA)
Use ONLY q+enter to exit. It's possible to break out by repeatedly typing q+enter+q+enter+q+enter until the end of time no matter what the console shows.
Here's a reasonable approximation:
p4log () {
p4 changes "$1" | awk '{print $2}' | xargs -i p4 describe -du {} | less -F
}
Note that unlike git log -p
, an argument is mandatory. You can give a pattern like p4log ...
to run it against everything under the current directory recursively.
Details
p4 changes "$1"
: Get one-line change summaries (most recent to oldest) for files matched by the pattern.
awk '{print $2}'
: Extract the change number.
p4 describe -du CHANGE [$CHANGE2 etc]
: Output the complete change description and diffs. The -du specifies unified diff format, which is closest to git's diff format.
xargs -i p4 describe -du {}
: Run the describe command with all the change numbers as its arguments.
less -F
: Page if longer than one screen, dump to terminal otherwise. Git pipes most of its output through less -F by default
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With