Git diff says no newline at end of file

When running git diff, you may meet it says “No newline at end of file”. Obviously the message tells there is a newline at the end for a file and there isn’t for the other. But is it a big deal? What’s the point of newline at end of file? w

Yes, it matters. It’s not only about good or bad styles to or not to add a newline to end of a file. It may lead to unexpected result if there is not a newline in the end of a file. For example when you run wc -l test.txt to get the count of lines, it would output a number with one line fewer for there is not a newline in the end. Furthermore, newline in the end is required for some language compilers. Therefore, always add a newline in end of file.

Setting up Beyond Compare as difftool and mergetool in Git

Set up Becond Compare as difftool and mergetool in Git. Last updated: 2018-12-18

Environment: Windows, Git v2.13.2

You can use git commands or directly edit global git config file to configure Beyond Compare as difftool and mergetool.

Method 1 : use git commands

# Config Beyond Compare 4 as difftool

$ git config --global diff.tool bc4
$ git config --global difftool.prompt false
# Note: set parameters for Beyond Compare tool
$ git config --global difftool.bc4.cmd '"C:\Program Files\Beyond Compare 4\BCompare.exe" "$LOCAL" "$REMOTE"' 

# Config Becond Compare 4 as mergetool

$ git config --global merge.tool = bc4
$ git config --global mergetool.prompt false
$ git config --global mergetool.bc4.path 'C:\Program Files\Beyond Compare 4\BCompare.exe'

Method 2 : directly edit global git config file

Edit git global git file .gitconfig in your home directory and add below contents:

[diff]
    tool = bc4
[difftool]
    prompt = false
[difftool "bc4"]
    cmd = "\"C:\\Program Files\\Beyond Compare 4\\BCompare.exe\" \"$LOCAL\" \"$REMOTE\""
[merge]
    tool = bc4
[mergetool]
    prompt = false
[mergetool "bc4"]
    path = C:\\Program Files\\Beyond Compare 4\\BCompare.exe

Showing difference in Git

git diff command shows difference between commits, commit and working tree, commit and staging area, working tree and staging area, etc.

Note: If you want to show difference in a visible tool, git difftool works for you. It accepts the same options as git diff .

The default difftool used by Git is vimdiff, you can set up your own difftool like Beycond Compare, see

Setting up Beyond Compare as difftool and mergetool in Git

Difference between commits

# Difference between two commits
$ git diff  

# Examples:
# Difference between HEAD's parent and HEAD
$ git diff HEAD~ HEAD

If you just want to show difference for a file, add -- :

# Difference between HEAD's parent and HEAD for index.php
$ git diff HEAD~ HEAD -- ./index.php

Difference between working tree and staging area

In other words, the , the below command show the untagged changes :

# Difference between working tree and staging area
$ git diff

Difference between working tree and commit

# Difference between working tree and commit
$ git diff 

# Examples:

# Difference between working tree and commit specified by '323552e'
$ git diff 323552e

Difference between staging area and commit

# Difference between staging area and commit
$ git diff --cached []

# Examples:

# Difference between staging area and HEAD. In other words, show the changes to be committed
$ git diff --cached

# Difference between staging area and HEAD~
$ git diff --cached HEAD~