Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between git-log and git-whatchanged?

Tags:

git

git-log

  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?

like image 997
Alexander Bird Avatar asked Apr 05 '12 04:04

Alexander Bird


People also ask

What is the difference between git log and git log?

log is that the log is a public accounting of the repository's commit history while the reflog is a private, workspace-specific accounting of the repo's local commits. The Git log is part of the Git repository and is replicated after a push, fetch or pull. In contrast, the Git reflog is not part of the replicated repo.

What is git log?

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) author. date.

Why do we use git log?

Git log is a utility tool to review and read a history of everything that happens to a repository. Multiple options can be used with a git log to make history more specific. A commit hash, which is a 40 character checksum data generated by SHA (Secure Hash Algorithm) algorithm.

What is git log -- stat?

The --stat option displays the number of insertions and deletions to each file altered by each commit (note that modifying a line is represented as 1 insertion and 1 deletion). This is useful when you want a brief summary of the changes introduced by each commit.


3 Answers

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)

like image 179
VonC Avatar answered Oct 05 '22 20:10

VonC


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.

like image 23
GoZoner Avatar answered Oct 05 '22 21:10

GoZoner


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

like image 24
bernardo Avatar answered Oct 05 '22 21:10

bernardo