I'm trying to export a list of changed files from two commits with git, with this command:
read -ra ADDR <<< `git diff --name-only HEAD..HEAD~1 | sed -e "s/ /\\\ /g"`
for i in "${ADDR[@]}"; do
echo "$i"
done
This works fine. I get a nice list printed out to the terminal with each file on a new row.
file1.txt
file2.txt
file3.txt
However, I want to use --name-status
instead of --name-only
. The reason is so I can later do different things depending on what kind of change was made (e.g. M or D).
This doesn't work though. I get a list in the following format:
M
file1.txt
M
file2.txt
M
file3.txt
I have tried to changed the IFS
variable to $'\n'
(returns everything on one row), $'\t'
(returns first row, e.g. M file1.txt
) and ' '
(same as \t
) without success.