43
  1. Given this answer to another question, and
  2. given that the man pages for both git-log and git-whatchanged say they pull from git-rev-list...

...what then is the difference between the two commands? Why bother having both of them?

1
  • 2
    A recent commit (August 2013) now clarifies the difference between the two commands, and encourages to use only git log. See my answer below Commented Sep 3, 2013 at 6:12

4 Answers 4

46

The commit 52f425e1 (August, 30th 2013) mentions:

Encourage new users to use 'log' instead. These days, these commands are unified and just have different defaults.

'git log' only allowed you to view the log messages and no diffs when it was added in early June 2005. It was only in early April 2006 that the command learned to take diff options.
Because of this, power users tended to use 'whatchanged' that already existed since mid May 2005 and supported diff options.


That is what the new version of the man page for git whatchanged will say now:

New users are encouraged to use git log instead. The whatchanged command is essentially the same as git log but defaults to show the raw format diff output and to skip merges.

The command is kept primarily for historical reasons; fingers of many people who learned Git long before git log was invented by reading Linux kernel mailing list are trained to type it.

As torek comments, the git whatchanged equivalent would be:

git log --raw --no-merges 

(That would avoid this question)

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for coming back and adding that. In general, I think the whole git community quite thankful for you, Charles Bailey, Jakub Narębski, and anyone else who puts this much time into the git questions on SO :).
Probably should mention that you can use git log --raw --no-merges to get the same effect without using the nominally-deprecated command.
@torek Thank you. I have seen stackoverflow.com/q/54412432/6309, so I have updated this answer accordingly.
13

In their simplest form, 'git log' shows each commit (sha, author, date, message) whereas 'git whatchanged' shows the commit plus files that changed. For example:

$ git log commit db9f525674443314a9822a6bd6c3acce49c8f8d6 Author: ... Date: Wed Apr 4 22:55:33 2012 -0700 Add more commit eed0b7aa3cad5d985b5f1d52f3c0605339c119a1 Author: ... Date: Tue Apr 3 20:36:04 2012 -0700 del bing/one.c 

but for whatchanged:

$ git whatchanged commit db9f525674443314a9822a6bd6c3acce49c8f8d6 Author: ... Date: Wed Apr 4 22:55:33 2012 -0700 Add more :100644 100644 f2e4113... d415016... M bar.c commit eed0b7aa3cad5d985b5f1d52f3c0605339c119a1 Author: ... Date: Tue Apr 3 20:36:04 2012 -0700 del bing/one.c :100644 000000 e69de29... 0000000... D bing/one.c 

Plenty of options exist to change the output of each command. For example 'git whatchanged -p' shows the changes in diff/patch form.

6 Comments

Thank you. Is there any functionality one command can do that the other simply can't?
It appears that the answer is 'no'. Looking at the git source code shows that the two are identical other than the default options. 'git log' will 'always show header'; 'git whatchanged' will always 1) show diff output, 2) simplify history and 3) use a raw diff format by default.
git-whatchanged doesn't include merges by default while git-log does. I haven't found the options, if there are any, to get git-log to output the list of changed files in the same way as git-whatchanged.
@Ken - You can use git-log --stat to show a list of changed files (and IMO a nicer list than git-whatchanged, since it shows the number of changed lines and supports color).
@ThaDon That looks like :oldmode newmode oldobjecthash newobjecthash.
|
5

Arguably git whatchanged is effectively equal to

git log --raw --no-merges 

And this is only “arguably” because of a very minor difference: you will get different timestamps if the range happens to have empty commits (commits with the same tree as the predecessor (if not a merge commit)).

git-whatchanged(1) is deprecated [1] since Git 2.51.0

This matters because git-whatchanged(1) is deprecated since Git 2.51.0. The command will error out unless you pass the option --i-still-use-this. So any scripts which use this command will stop working.

Notes

  1. Deprecated in a way that affects you as a user. In reality the command has been deprecated since 2013 (that’s what the author intended with that change).

1 Comment

Actually, git whatchanged is deprecated since 2013. Git 2.51.0 marks the version that designates the command for removal.
3

I don't totally agree. Can you see merge changed files with log?

I didn't find this functionality and is very useful for to know when a file was merged in some branch, example:

file c.c in branch1 has a commit date from 1/1/2012, if you do a merge to branch2, and later would like to follow the day that that commit was introduced in branch2, can git log help? If you have the merges you could search in them with git whatchanged -m sha1

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.