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:
b.filec.filed.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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With