Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display unchanged files in git diff

Tags:

git

diff

I am comparing a path on two branches with git to prepare for merge. I want to list all files under this path, and their status with git diff, not only changed files.

Example:

I have a repository, currently on branch main, which has 3 files:

$ git status
On branch main
nothing to commit, working tree clean

$ ls -1
a.file
b.file
c.file

On a second branch new-branch, I perform three changes:

  • delete b.file
  • change c.file
  • create d.file
$ git status
On branch new-branch
nothing to commit, working tree clean

$ ls -1
a.file
c.file
d.file

Using git diff I can list the names and statuses of all changed files:

$ git diff --name-status main new-branch
D       b.file
M       c.file
A       d.file

This is almost exactly what I want: I would also like to find a.file in this list. Something like this:

        a.file
D       b.file
M       c.file
A       d.file

Is this possible with git diff? Perhaps with git show?

like image 327
LodeRunner Avatar asked Oct 27 '25 04:10

LodeRunner


1 Answers

Please use following code.

git ls-files | while read -r line;
do
    st=$(git diff --name-status main new-branch "$line");
    if [ -n "$st" ]; then
        echo "$st";
    else
        echo "   $line";
    fi;
done

git ls-files: show all files controlled by Git.

git diff --name-status main new-branch "$line" We will use git diff for specific file.

Note: You just need to paste the above code into terminal.

like image 72
Thân LƯƠNG Avatar answered Oct 28 '25 18:10

Thân LƯƠNG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!