5

I am reviewing a very old commit. I want to see the changes a particular commit made but I want to see that in full context, i.e. I want to see whole file and the changes that person had made. The following command,

git show -w <commit-id>

is not showing me full context. Any suggestion?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
MAG
  • 2,841
  • 6
  • 27
  • 47
  • Tried `git log -p commit-id` ? – chridam Jan 09 '15 at 10:04
  • that command also does not gives me full file . It shows few lines only – MAG Jan 09 '15 at 10:07
  • @MAG Any feedback on my answer or jas_raj's? – jub0bs Jan 12 '15 at 08:27
  • @Jubobs Thanks a lot for your help and your time . I am on a very old version of git and hence git-show is not present on my machine . git blame output is very badly formatted since my aim was to understand some part of the code . So I resorted to git show -w plain with full code opened side by side – MAG Jan 12 '15 at 17:19
  • 1
    @MAG Ah sorry, there was a misunderstanding. Git verbs are sometimes written with a hyphen in text. I really meant the `git show` you know. About my answer, doesn't `git show -U1000 ` do what you want? – jub0bs Jan 15 '15 at 12:03
  • ohh thanks @Jubobs . yes it did . thanks for the additional information that "Git verbs are sometimes written with a hyphen in text." – MAG Jan 17 '15 at 01:25
  • `-W` is very handy, too. – Geremia Dec 07 '18 at 18:08

2 Answers2

7

git-show comes with the following flag

-U<n>, --unified=<n>
    Generate diffs with <n> lines of context instead of the usual
    three. Implies -p.

See the git-show man page for more details. By specifying a large enough <n>, e.g.

git show -U1000 <object>

you will get full context.

Example

Clone some repository for the sake of this example (e.g. the Git project's repo):

$ git clone https://github.com/git/git
$ cd git

Try running the command in question on some committed file (e.g. Documentation/RelNotes/2.3.0.txt):

$ git show -U100 -- Documentation/RelNotes/2.3.0.txt
commit 1e6f5b22ad318446500fbd3b94b733eddd5b6414
Author: Junio C Hamano <gitster@pobox.com>
Date:   Wed Jan 7 13:12:54 2015 -0800

    Fourth batch for 2.3 cycle

    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/Documentation/RelNotes/2.3.0.txt b/Documentation/RelNotes/2.3.0.txt
index 1b1dcbb..7f25bbf 100644
--- a/Documentation/RelNotes/2.3.0.txt
+++ b/Documentation/RelNotes/2.3.0.txt
@@ -1,165 +1,247 @@
 Git v2.3 Release Notes
 ======================

 Updates since v2.2
 ------------------

 Ports

  * Recent gcc toolchain on Cygwin started throwing compilation warning,
    which has been squelched.


 UI, Workflows & Features

  * It was cumbersome to use "GIT_SSH" mechanism when the user wanted
    to pass an extra set of arguments to the underlying ssh.  A new
    environment variable GIT_SSH_COMMAND can be used for this.

  * A request to store an empty note via "git notes" meant to remove
    note from the object but with --allow-empty we will store a
    (surprise!)  note that is empty.

  * "git interpret-trailers" learned to properly handle the
    "Conflicts:" block at the end.

  * "git am" learned "--message-id" option to copy the message ID of
    the incoming e-mail to the log message of resulting commit.

+ * "git clone --reference=<over there>" learned the "--dissociate"
+   option to go with it; it borrows objects from the reference object
+   store while cloning only to reduce network traffic and then
+   dissociates the resulting clone from the reference by performing
+   local copies of borrowed objects.
+
  * "git send-email" learned "--transfer-encoding" option to force a
    non-fault Content-Transfer-Encoding header (e.g. base64).
...

Sanity check

Compare the output of that command to the contents of Documentation/RelNotes/2.3.0.txt.

$ cat Documentation/RelNotes/2.3.0.txt
Git v2.3 Release Notes
======================

Updates since v2.2
------------------

Ports

 * Recent gcc toolchain on Cygwin started throwing compilation warning,
   which has been squelched.


UI, Workflows & Features

 * It was cumbersome to use "GIT_SSH" mechanism when the user wanted
   to pass an extra set of arguments to the underlying ssh.  A new
   environment variable GIT_SSH_COMMAND can be used for this.

 * A request to store an empty note via "git notes" meant to remove
   note from the object but with --allow-empty we will store a
   (surprise!)  note that is empty.

 * "git interpret-trailers" learned to properly handle the
   "Conflicts:" block at the end.

 * "git am" learned "--message-id" option to copy the message ID of
   the incoming e-mail to the log message of resulting commit.

 * "git clone --reference=<over there>" learned the "--dissociate"
   option to go with it; it borrows objects from the reference object
   store while cloning only to reduce network traffic and then
   dissociates the resulting clone from the reference by performing
   local copies of borrowed objects.

 * "git send-email" learned "--transfer-encoding" option to force a
   non-fault Content-Transfer-Encoding header (e.g. base64).

 * "git send-email" normally identifies itself via X-Mailer: header in
   the message it sends out.  A new command line flag --no-xmailer
   allows the user to squelch the header.

 * "git push" into a repository with a working tree normally refuses
   to modify the branch that is checked out.  The command learned to
   optionally do an equivalent of "git reset --hard" only when there
   is no change to the working tree and the index instead, which would
   be useful to "deploy" by pushing into a repository.

 * "git new-workdir" (in contrib/) can be used to populate an empty
   and existing directory now.
jub0bs
  • 60,866
  • 25
  • 183
  • 186
1

From this post, the following will give you the file as it looked at the specific commit:

  git show REVISION:path/to/file

EDIT: Based on the comments below, it's been highlighted the above might not be quite with the OP was asking.

In order to get the file at the particular version along with the changes and the author of each line, you should instead use:

  git blame REVISION path/to/file
Community
  • 1
  • 1
jas_raj
  • 1,131
  • 6
  • 14
  • I don't think that's what the OP wants. S/he writes "I want to see the changes a particular commit made [...]". I understand this as seeing the diff between the commit in question and one of its parents. The command you give will simply print the whole revision stored in ``; it won't show the *changes* introduced by that commit. – jub0bs Jan 09 '15 at 13:34
  • 1
    @shkschneider The OP also writes: *I want to see whole file and the changes that person had made*. I may be wrong, but I don't think there is room for ambiguity, here. – jub0bs Jan 09 '15 at 16:22