Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

p4 command line equivalent to “git log -p”?

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:

  • what was the last .cpp file to be modified?
  • find all commits where the string FOO has been added to a file.
  • a function just got deprecated; what did other developers replace it with?
  • in general, just know what happened recently in a given directory.
like image 612
sam hocevar Avatar asked Mar 19 '14 11:03

sam hocevar


People also ask

What is git log P?

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.

Is log a git command?

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)

How do I exit git log Powershell?

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.


1 Answers

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

like image 144
daxelrod Avatar answered Sep 22 '22 16:09

daxelrod