拆分git的差异由换行符--name状态 [英] Split git diff --name-status by line break
问题描述
我想从两个提交出口文件改变列表使用Git,用这个命令:
阅读-ra ADDR<<< `git的差异--name只HEAD..HEAD〜1 | SED -eS / / \\\\\\ / G`
因为我在$ {ADDR [@]};做
回声$ I
DONE
这工作正常。我得到打印出来的终端与新行的每个文件一个漂亮的清单。
FILE1.TXT
FILE2.TXT
file3.txt
不过,我想用 - 名状态
而不是 - 名称仅
。原因是这样我以后会做不同的事情取决于被做了什么样的变化(例如M或D)。
这不,虽然工作。我得到以下格式的列表:
中号
FILE1.TXT
中号
FILE2.TXT
中号
file3.txt
我试图改变 IFS
变量 $的'\\ n'
(上一行返回的一切) , $'\\ t'
(返回第一行,如中号FILE1.TXT
)和 ''
(等同于 \\ t
)没有成功。
同时读取状态ADDR
做
回声$ ADDR($ STATUS)
完成< ≤(git的差异--name状态HEAD..HEAD〜1)
例如。像
git的输出 中号INSTALL
中号的debian /更新日志
中号的src / lib中/ libnvpair / SConscript
中号的src / lib中/ libzfscommon / SConscript
中号的src / lib中/ libzpool / SConscript
中号的src / ZFS的保险丝/ main.c中
由while循环打印以下内容:
安装(M)
的debian /更新日志(M)
SRC / lib目录/ libnvpair / SConscript(M)
SRC / lib目录/ libzfscommon / SConscript(M)
SRC / lib目录/ libzpool / SConscript(M)
SRC / ZFS的保险丝/ main.c中(M)
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.
while read STATUS ADDR
do
echo "$ADDR ($STATUS)"
done < <(git diff --name-status HEAD..HEAD~1)
E.g. for git output like
M INSTALL
M debian/changelog
M src/lib/libnvpair/SConscript
M src/lib/libzfscommon/SConscript
M src/lib/libzpool/SConscript
M src/zfs-fuse/main.c
the following is printed by the while loop:
INSTALL (M)
debian/changelog (M)
src/lib/libnvpair/SConscript (M)
src/lib/libzfscommon/SConscript (M)
src/lib/libzpool/SConscript (M)
src/zfs-fuse/main.c (M)
这篇关于拆分git的差异由换行符--name状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!