How to Show Conflicted Files in Git

John Wachira Feb 15, 2024
How to Show Conflicted Files in Git

This article discusses the simplest and cleanest way to list conflicted files in Git. We could use the git status command, but this is messy, especially if we have tons of un-conflicting files.

A simpler and cleaner way employs the git diff command, as we will see shortly.

Show Conflicted Files in Git

As mentioned earlier, we can use the git status command to list conflicting files. Here is an example.

We have attempted to merge two branches with conflicting files in the example below. Running the git status command will give:

$ git status

git status

However, if we have a lot of un-conflicting and conflicting files, the output will be messy. A simple and cleaner way of listing conflicting files involves the git diff command.

If we want to check conflicting files in our repo, we will run:

$ git diff --name-only --diff-filter=u

git diff

We employ the git diff command with the --name-only flag to only show the names of the files conflicting. We have also added the --diff-filter=u to only include unmerged files.

We can create an alias for this command to make our work easier. To do so, we will have to add the alias to our .config file, as shown below.

$ git config --global alias.conflicts "diff --name-only --diff-filter=u"

Now we can use conflicts instead of the whole command, as shown below.

$ git conflicts

git conflicts

In conclusion, the git status command is not always ideal for listing conflicting files in Git. You may get messy output if you are dealing with a large number of files.

As illustrated above, a simpler and cleaner way involves the git diff command.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn